Same conditional formatting if same value

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,185
Hi,

Is there a way to get some kind of dynamic conditional formating: if A1 = B1, then A1 formating =B1 formating (font and text color).

I thought of a macro on a change value event but I miss the "undo" function.

Any idea? Thanks in advance
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Re: Same condiational formating if same value

Maybe something like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRange As Range, rDefaultFormat As Range
    
    Set MyRange = Range("A1:A10") '<--adjust to suit
    Set rDefaultFormat = Range("Z1") '<--adjust
    
    If Not Intersect(Target, MyRange) Is Nothing Then
        Application.EnableEvents = False
        If UCase(Target.Value) = UCase(Target.Offset(, 1).Value) Then
            Target.Offset(, 1).Copy
            Target.PasteSpecial Paste:=xlPasteFormats
        Else
            rDefaultFormat.Copy
            Target.PasteSpecial Paste:=xlPasteFormats
        End If
        Application.EnableEvents = True
        Application.CutCopyMode = False
    End If
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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