I tried to make a conditioanl format by using VBA program (Refer to VBA code below). Howerver, if I used reference "$A2." in the conditional format in the program, then there were a random error showed in debug information below. For exmaple, sometimes conditional format added in excel become "$A1048559" rather than "$A2". If I used reference '$A$2", then there is no such problem. So what is the problem here?
--------------------------------------------------------------------------------------------------
Sub ccc()
Dim i as integer
i = 2
With Range("B" & i & ":AE" & i)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=OR($A" & i & "=""BAD"", $A" & i & "=""TOBE"")"
.FormatConditions(1).Font.ColorIndex = 3
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$A" & i & "=""SKIP"""
.FormatConditions(2).Font.ColorIndex = 15
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$A" & i & "=""OK"""
.FormatConditions(3).Font.ColorIndex = 1
.Font.Bold = True
End With
Debug.Print Now & " After:" & Cells(2, 2).FormatConditions.Item(1).Formula1
End Sub
------------------------------------------------------------------------------------------------
debug information
2012/6/10 0:54:56 After£º=OR($A2="BAD", $A2="TOBE")
2012/6/10 0:55:01 After£º=OR($A2="BAD", $A2="TOBE")
2012/6/10 0:55:06 After£º=OR($A2="BAD", $A2="TOBE")
2012/6/10 0:55:25 After£º=OR($A1048559="BAD", $A1048559="TOBE")
Bookmarks