Compare two documents or sheets side by side

Alex Sanchez

New Member
Joined
Jun 26, 2007
Messages
49
Hello there,

Is there a way to compare two documents or sheets side by side and have excel tell you or highlight a cell if it doesn't match with the other cell in the other docoment or sheet.

Thanks,

Alex
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hello Alex Sanchez, welcome to the board.
There are likely quicker ways to do this (most especially if these are really huge data sets)
but this is about as robust a method as I can think of.
Code:
Sub CompareSheets()
Dim c1 As Range

If Sheets("Sheet1").UsedRange.Cells.Count <> _
   Sheets("Sheet2").UsedRange.Cells.Count Then
     MsgBox "These sheets have different amounts of data. They do not match.", , "Different Range Sizes"
     Exit Sub
End If

For Each c1 In Sheets("Sheet1").UsedRange
  If Not c1.Value = Sheets("Sheet2").Cells(c1.Row, c1.Column).Value Then
    MsgBox "cell " & c1.Address(0, 0) & " does not match in both sheets.", , "Non Match Found"
    With c1.Font
      .ColorIndex = 3
      .Bold = True
    End With
  End If
Next
End Sub

Hope it helps.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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