conditional formatting in excel vba

L

lijia137

I have a workbook with several worksheets, i need to do conditional
formatting to column B on each worksheet, does excel conditional
formatting only take up to 3 conditions? cuz my formular is like: if
E2=Y and F2>2, code B2 in blue; if E2=Y and F2<0, code B2 in red,
basically, cells in column B changes color based on colume E and
Colume F, i was recoding macro while doing the conditional formatting,
here is what i wrote: seems macro can't take the last selection? could
somebody help me? thanks a ton!!!

Sub Macro5_ColorCoding()
'
' Macro5_ColorCodingSat Macro
' '

'
Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression,
Formula1:="=E2=Y"
Selection.FormatConditions.Add Type:=xlExpression,
Formula1:="=F2>0"
With Selection.FormatConditions(2).Font
.Bold = True
.Italic = False
.ColorIndex = 5
End With
Selection.FormatConditions.Add Type:=xlExpression,
Formula1:="=E2=Y"
Selection.FormatConditions.Add Type:=xlExpression,
Formula1:="=F2<0"
With Selection.FormatConditions(3).Font
.Bold = True
.Italic = False
.ColorIndex = 3
End With
End Sub
 
J

Joel

The limit of three conditions refers to the number of diffferent colors each
would be a diffferrent formula (Formula1, formula2, formula3). Ffor each
formula you can have an IF statement with multiple conditions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top