vba conditional formatting

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

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

VBA - Conditional Formatting

resolvedResolved · Medium Priority · Version 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.

 

Training courses

 

Training information:

See also:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Editing a formula quickly

If you want to edit a fomrula or text quickly witin a cell instead of the formula bar, you can click either double click in the cell or press the F2 key

View all Excel hints and tips


Server loaded in 0.08 secs.