VBA to compare rows in two different sheets, if match highlight cell

JeremyG12

New Member
Joined
Feb 13, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello. New to this board. I found some code that compares two worksheets (sheet 2 with sheet 1) to determine if there are any differences in the rows. The code works perfect for highlighting the entire row. If there is a difference in the row on sheet 2, it is highlighted in red. Instead of highlighting the entire row, I would like to highlight the cell(s) where a change was found in each row.

Set Ws1 = Sheets("Sheet1")
Set Ws2 = Sheets("Sheet2")
Lc = Ws2.Cells(1, Columns.Count).End(xlToLeft).Column
With CreateObject("scripting.dictionary")
For Each cl In Ws1.Range("A2", Ws1.Range("A" & rows.Count).End(xlUp))
Vlu = Join(Application.index(cl.Resize(, Lc).Value, 1, 0), "|")
.Item(Vlu) = Empty
Next cl
For Each cl In Ws2.Range("A2", Ws2.Range("A" & rows.Count).End(xlUp))
Vlu = Join(Application.index(cl.Resize(, Lc).Value, 1, 0), "|")
If .exists(Vlu) = False Then cl.Resize(, Lc).Interior.color = RGB(250, 0, 0)
Next cl
End With
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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