conditional formatting and VBA

oswalda

New Member
Joined
May 27, 2024
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I need a vba script that will highlight the cells in column B that do not equal the value in the same row in column A as illustrated below
conditional formatting.png


Made several attempts, can't get it to work
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Like this ?

VBA Code:
Sub Macro1()


    Dim rng As Range
    
    For Each rng In Range("A1:A5")
    
        If rng.Value <> rng.Offset(, 1).Value Then
            rng.Offset(, 1).Interior.Color = vbYellow
        End If
        
    Next

End Sub


1716864584907.png
 
Upvote 0
In this line: rng.Offset(, 1).Interior.Color = vbYellow I took out "Offset(,1). and it worked for that pair of columns perfectly thanks for that.

I used the same script for another pair and got a "type mismatch error" The second pair compares names instead of dates.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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