Compare two columns in different sheets, highlight unique values.

Scoober

New Member
Joined
Sep 7, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I would like a to have a VBA script that compares two columns that are in different sheets and highlights the unique values in sheet 1. As below:
Sheet 1 Sheet2
Column A Column A
Apple Apple
Orange Pineapple
Pineapple Orange
Pear Coconut
Tomato

Transformed With VBA to:

Sheet 1 Sheet2
Column A Column A
Apple Apple
Orange Pineapple
Pineapple Orange
Pear Coconut
Tomato

So it is Sheet 1's column that is compared to Sheet2 no highlighting needed in sheet2 there can be unique values in that one.

Thank you for your help!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
my apologies the spaces went away in my example, so its a bit unclear. The "tomato" value is in sheet 2 column so not highlighted
 
Upvote 0
MAby something like this:
VBA Code:
Option Explicit
Sub highlight()
Dim lr&, r1 As Range, r2 As Range, cell As Range
With Sheets("Sheet2")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    Set r2 = .Range("A1:A" & lr)
End With
With Sheets("Sheet1")
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    Set r1 = .Range("A1:A" & lr)
    For Each cell In r1
        If r2.Find(cell.Value) Is Nothing Then cell.Font.Color = vbRed
    Next
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

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