Quote:
Originally Posted by mEmmerrr
Is it possible to run an if function, with the logical test being the colour of text in a box?
Definitely possible with VBA - don't think it's possible without that. You'd probably want to use conditional formatting?
For VBA:
Sub colortest()
If Range("c3").Interior.ColorIndex = "1" Then
Range("a1").Value = "yes"
Else
Range("a1").Value = "no"
End If
End Sub
Here's a
link for a color index. ColorIndex "1" is black.
If you're using excel formats....
Sub colortest()
If Range("c3").Style = "Good" Then
Range("a1").Value = "yes"
Else
Range("a1").Value = "no"
End If
End Sub
The styles are case sensitive ("Good" works, but not "good").
You can record macros to figure out what the different styles are called, though they're probably just their names.
To expand on this, if using a macro isn't your thing, you can actually make this a custom function using VBA.
Technically, you're still using VBA, but you don't need to use a macro to get the benefits
If it's column C that you're testing, you'd put +if(colortest1(c1) = "whatever you're testing for", "yes","no")
To make this work, go to the VBA editor (alt+f11), then click on the insert menu, and select insert module. Then paste the below:
Function colortest1(range)
colortest1 = range.Style
End Function
If you're testing for color rather than an established excel style it's:
Function colortest1(range)
colortest1 = range.interior.ColorIndex
End Function
Last edited by ret44; 10-16-2010 at 11:34 PM.
Reason: Silly extra coding step