PDA

View Full Version : Conditional Formatting using VBA



KarNeedsHelp
06-21-2011, 11:04 AM
Hi I want to write a Macro that will compare data from two cells and then format accordingly.

I don't want to manually set each cell with conditional format because the #of data differs each day, and there are close to 600 values.

I have data in Column B and C everyday, so I want to use something like check the lastrow with value in it.

The Condtional Formatting will go like this

Data starts with cell B3:
For cell B4
If B4>B3, format interior blue
If B4<B3, yellow
If B4=B3, no color

Then it moves on to the next cell B5:
If B5>B4, format interior blue
If B5<B4, yellow
If B5=B4, no color

Then it keeps on doing it until the last cell in the column.

omnibuster
06-21-2011, 11:51 AM
Try.
Sub CondLoop()
Range("B4").Activate
Do Until ActiveCell = ""

Select Case ActiveCell
Case Is < ActiveCell.Offset(-1, 0).Value
ActiveCell.Interior.ColorIndex = 6

Case Is > ActiveCell.Offset(-1, 0).Value
ActiveCell.Interior.ColorIndex = 33

Case Is = ActiveCell.Offset(-1, 0).Value
ActiveCell.Interior.ColorIndex = xlNone

End Select

ActiveCell.Offset(1, 0).Activate
Loop
End Sub

xld
06-21-2011, 03:01 PM
Why use VBA, why not just standard CF?