Conditional Formatting

canischintsomani

New member
Joined
Jun 5, 2014
Messages
3
Reaction score
0
Points
0
Hello

I need VB code for conditional formatting for following criteria

if the cell value in column b is grater than cell value in column a, cell in column should b should turn in to green, if it is lesser than it should turn in to red, and if its equal no change.

i know this can be resolved with conditional formatting option in excel, but in that case i have to apply on each cell one by one.

my data base is too big, so i want solution with VB codes.

Thanks a ton
 
You don't have to apply to each one separately, just select the whole range, and use a formula that applies to the first in the selection. Excel will handle the automatic adjustment.
 
Thanks Bob.. its working now.. but if possible can you please provide vb codes also..
 
I would so the same in VBA

Code:
    With Range("B2:B5")    
        For i = .FormatConditions.Count To 1 Step -1
        
            .FormatConditions(i).Delete
        Next i
        
        .FormatConditions.Add Type:=xlExpression, Formula1:="=B2>A2"
        With .FormatConditions(1)
        
            .Interior.ColorIndex = 35
        End With
    End With
 
Last edited:
Back
Top