Conditional Formatting

Closed
Badgermd163 - Sep 26, 2008 at 04:20 AM
Ivan-hoe Posts 433 Registration date Saturday February 16, 2008 Status Member Last seen October 17, 2008 - Sep 26, 2008 at 06:00 AM
I need to specify different text colours for certain conditions. This I can do with the conditional formatting but only for three conditions, I have tried to write some VBA code to allow me to call two or more routines to get more conditions The code only partially works, can anyone tell me where i am going wong, I am sure that this can be done. Code below. Thanks Badger163.

Sub Audit1()

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""no"""
Selection.FormatConditions(1).Interior.ColorIndex = 3

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""?"""
Selection.FormatConditions(2).Interior.ColorIndex = 3
Audit 2
End Sub

Sub Audit2()

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""/"""
Selection.FormatConditions(1).Interior.ColorIndex = 8

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""yes"""
Selection.FormatConditions(2).Interior.ColorIndex = 8

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
Formula1:="=""n/a"""
Selection.FormatConditions(3).Interior.ColorIndex = 8

End Sub
,

1 response

Ivan-hoe Posts 433 Registration date Saturday February 16, 2008 Status Member Last seen October 17, 2008 110
Sep 26, 2008 at 06:00 AM
Hello Badger,
Actually you need only 2 conditions, since you use only two different formattings : green or red.
No VBA needed, use a formula in your conditionnal formatting instead.
Condition 1: =OR(A1="no";A1="?") ---> red colour
Condition 2: =OR(A1="/";A1="yes";A1="#N/A") --> green colour
Ivan.
1