PDA

View Full Version : Conditional statement in a macro



maninjapan
07-13-2009, 11:53 AM
Id just like to write a simple macro that will go through a table of figures and highlight cells that meet a certain criteria (ie IF cell > 0.5 THEN color blue). Im not quite sure how to write that part.

Any help would be much appreciated.

Thanks.

p45cal
07-13-2009, 12:08 PM
Sub blah()
'For Each cll In Selection.Cells
For Each cll In Range("B3:G37").cells
If cll.Value > 0.5 Then cll.Interior.ColorIndex = 41
Next cll
End Sub

maninjapan
07-13-2009, 12:28 PM
Thanks p45. very simple... One more question, how do I I make it only color cells with numbers (its coloring all the cells with letters as well)

Thanks

mdmackillop
07-13-2009, 01:37 PM
Test for numbers as well

If IsNumeric(cll) And cll.Value > 0.5 Then cll.Interior.ColorIndex = 41