VBA code for comparing two sheets in same workbook

shukrp

New Member
Joined
Jun 18, 2018
Messages
8
Hi Guy's,


I have vba code for comparing value in two sheets in same workbook which compare data and highlights difference's with color in both the sheets however it has uppercase and lowercase issue so I would like to modify this code to resolve uppercase and lowercase issue. Extra space is another issue so need help for that too.


Code is as follows :

Code:
Public Sub CompareSheets()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim cell As Range, rng As Range
Set ws2 = Worksheets("XYZ")
Set ws3 = Worksheets("Abcdefg")
Set rng = ws2.Range("A2:A500")
For Each cell In rng
    Celladdress = cell.Address
    If cell <> ws3.Range(Celladdress) Then
        cell.Interior.Color = vbRed
        ws3.Range(Celladdress).Interior.Color = vbRed
    End If
Next cell
Set rng = ws2.Range("B2:B500")
For Each cell In rng
    Celladdress = cell.Address
    If cell <> ws3.Range(Celladdress) Then
        cell.Interior.Color = vbYellow
        ws3.Range(Celladdress).Interior.Color = vbYellow
    End If

Next cell
End Sub


Any help would be much appreciated.

Thanks and regards,
Shuk
 
Last edited by a moderator:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try
Code:
If LCase(cell) <> LCase(Ws3.Range(Celladdress)) Then
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,224
Members
453,025
Latest member
Hannah_Pham93

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