Conditional Formatting using VBA

Swapnil_Next

New Member
Joined
Aug 17, 2014
Messages
6
I want to conditionally format a range of cells where data in a cell in a column is equal to data in corresponding cell in another column.

for example:

if the cell value of A1 is equal to the cell value of G1 then the A1:D1 from range(A1:D6) will get highlighted, and if the cell value of A2 is equal to the cell value of G2 then the A2:D2 from range(A1:D6) will get highlighted.

It works with Conditional Formatting but I want to do it using VBA.

Can anyone help on this?

Thanks in Advance,

Swapnl_Next
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
.
.

Try something like this:

Code:
Sub AddFormCond()

    With Range("A1:D6").FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="=$A1=$G1")
    
        .Interior.Color = RGB(198, 239, 206)
        .Font.Color = RGB(0, 97, 0)
    
    End With

End Sub
 
Upvote 0
.
.

Try something like this:

Code:
Sub AddFormCond()

    With Range("A1:D6").FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="=$A1=$G1")
    
        .Interior.Color = RGB(198, 239, 206)
        .Font.Color = RGB(0, 97, 0)
    
    End With

End Sub


It works very well. Thanks a lot!
 
Upvote 0
.
.

Try something like this:

Code:
Sub AddFormCond()

    With Range("A1:D6").FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="=$A1=$G1")
    
        .Interior.Color = RGB(198, 239, 206)
        .Font.Color = RGB(0, 97, 0)
    
    End With

End Sub

@ gpeacock,

I'd need nearly the same thing and I want to add this code to a Macro that I'm already using , basically I want that when column D EUR/USD Column C must be currency formatted accordingly (with EUR/USD)
PLEASE
 
Upvote 0
Perfect! Thank you!

.
.

Try something like this:

Code:
Sub AddFormCond()

    With Range("A1:D6").FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:="=$A1=$G1")
    
        .Interior.Color = RGB(198, 239, 206)
        .Font.Color = RGB(0, 97, 0)
    
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,222,437
Messages
6,166,023
Members
452,008
Latest member
Customlogoflipflops

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top