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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
.
.

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,213,534
Messages
6,114,188
Members
448,554
Latest member
Gleisner2

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