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

Comments

Alex said…
One day I ran into like trouble and fortunately only due to the one tool I could solve it. This program was found out at a soft portal. The program helped me and besides would be usable for almost every difficult condition - recover Excel file tools.

Popular posts from this blog

Outlook : "operation failed, object could not be found. " when trying to close a PST.

Troubleshooting Outlook Express (IMAP, POP3, HTTP, NEWS) with the log file

MSSQL GROUP_CONCAT