Kimberly has attended:
Excel Advanced course
Excel VBA Intro Intermediate course
VBA - Conditional Formatting
Hi Simon,
How do I go about writing the macro for conditional formatting?
Thanks,
Kim
RE: VBA - Conditional Formatting
Hi Kimberly
Thank you for your question
The following code cycles through each cell in a particular range and formats its font colour depending on its value
Sub Formatter()
Dim i As Integer
Dim varValue As Variant
Dim rngRange As Range
Set rngRange = Sheets(2).Range("E1:E9")
For i = 1 To rngRange.Rows.Count
varValue = rngRange(i, 1).Value
If IsNumeric(varValue) Then
Select Case varValue
Case Is < 2
rngRange(i, 1).Font.Color = vbBlue
Case Is < 5
rngRange(i, 1).Font.Color = vbRed
Case Is < 8
rngRange(i, 1).Font.Color = vbGreen
Case Else
rngRange(i, 1).Font.Color = vbBlack
End Select
End If
Next i
End Sub
Hope this is useful
Regards
Stephen