Excel VBA for conditional formatting.
Sub CreateConditionalFormatting()
Dim column As String
column = "C"
Dim NoOfRowNeeded As Integer
NoOfRowNeeded = 3000
Dim j As Integer
Dim cellSelect As String
For j = 1 To NoOfRowNeeded
cellSelect = column & CStr(j)
Range(cellSelect).Select
Selection.FormatConditions.Delete
If (j - 1) < 1 Then
Range(cellSelect).Interior.ColorIndex = 4
Else
'maximum 3 formula allowed.
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=INT(" & column & CStr(j - 1) & ") Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=INT(" & column & CStr(j - 1) & ")>INT(" & column & CStr(j) & ")"
Selection.FormatConditions(2).Interior.ColorIndex = 6
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=INT(" & column & CStr(j - 1) & ")=INT(" & column & CStr(j) & ")"
Selection.FormatConditions(3).Interior.ColorIndex = 4
End If
Next j
End Sub
Dim column As String
column = "C"
Dim NoOfRowNeeded As Integer
NoOfRowNeeded = 3000
Dim j As Integer
Dim cellSelect As String
For j = 1 To NoOfRowNeeded
cellSelect = column & CStr(j)
Range(cellSelect).Select
Selection.FormatConditions.Delete
If (j - 1) < 1 Then
Range(cellSelect).Interior.ColorIndex = 4
Else
'maximum 3 formula allowed.
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=INT(" & column & CStr(j - 1) & ")
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=INT(" & column & CStr(j - 1) & ")>INT(" & column & CStr(j) & ")"
Selection.FormatConditions(2).Interior.ColorIndex = 6
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=INT(" & column & CStr(j - 1) & ")=INT(" & column & CStr(j) & ")"
Selection.FormatConditions(3).Interior.ColorIndex = 4
End If
Next j
End Sub
Comments