Help With Compare And Highlight Macro

gaspower

Board Regular
Joined
Jun 10, 2005
Messages
55
Hello,

I have two sheets in a workbook. Column "A" is the model number and used for comparing in both sheets. I need to take sheet1 and compare to sheet2. All that match using column "A", I need to highlight in sheet2. I have been trying to modify the below macro, but no luck,

Sub greendifference()
Dim k As Long, e, a As Range, b As Range
Set a = Sheets("sheet1").Range("A1:ZZ760")
Set b = Sheets("sheet2").Range("A1:ZZ760")
For Each e In a
k = k + 1
If a(k) <> b(k) Then
a(k).Interior.Color = vbGreen
b(k).Interior.Color = vbGreen
End If
Next e
End Sub

Thanks JR
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try

Code:
Sub greendifference()
Dim LR As Long, i As Long, x As Variant
LR = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    x = Application.Match(Sheets("Sheet1").Range("A" & i).Value, Sheets("Sheet2").Columns("A"), 0)
    If IsNumeric(x) Then
        Sheets("Sheet1").Range("A" & i).Interior.Color = vbGreen
        Sheets("Sheet2").Range("A" & x).Interior.Color = vbGreen
    End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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