Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba conditional formatting

Forum home » Delegate support and help forum » Microsoft Excel Training and help » VBA - Conditional Formatting

VBA - Conditional Formatting

ResolvedVersion 2003

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

Fri 11 Sep 2009: Automatically marked as resolved.

Excel tip:

Adding cells, Rows & columns

place your cursor on a cell, row number or column letter and use CTRL + SHIFT + + or CTRL + + depending on which + you prefer to use.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.