Question : Compare two excel sheets 2007

Related to this one:  http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_25045946.html#a26288504

Is there a compare tool for Excel 2007 that will compare two different sheets and highlights the cells that are different.  Anyone have one that does that?  Free would be great, but even if it cost a little it would be worth it.
Thanks, Pat

Answer : Compare two excel sheets 2007


This code below will compare the used range of two sheets. It will

  • Produce an output sheet  (called "output") which will list the differences (in values, not formulas)
     
  • It will colour the different cells green in the first sheet  

It uses variant arrays rather than cell ranges so it will be quick

To use simply run the code, and follow the 2 step instructions to click on a single cell in each of the two sheets to be compared

Cheers

Dave
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
Sub CompareMe()
    Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Dim rng1 As Range, rng2 As Range, rng3 As Range
    Dim X1(), X2(), X3()
    Dim i As Long, j As Long
    Set ws1 = Application.InputBox("Click in any cell in the first sheet", "Select sheet1", , , , , , 8).Parent
    Set ws2 = Application.InputBox("Click in any cell in the second sheet", "Select sheet2", , , , , , 8).Parent
    If ws1.Name = ws2.Name Then
        MsgBox "You picked the same 2 sheets", vbCritical
        Exit Sub
    End If

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With

    Set rng1 = ws1.UsedRange
    Set rng2 = ws2.Range(rng1.Address)
    On Error Resume Next
    Sheets("Output").Delete
    On Error GoTo 0
    Set ws3 = Worksheets.Add
    ws3.Name = "Output"
    Set rng3 = ws3.Range(rng1.Address)
    X1 = rng1
    X2 = rng2
    X3 = rng3
    For i = 1 To UBound(X1, 1)
        For j = 1 To UBound(X1, 2)
            If X1(i, j) <> X2(i, j) Then
            X3(i, j) = "'" & X1(i, j) & " v " & "'" & X2(i, j)
            rng1.Cells(i, j).Interior.ColorIndex = 4
            End If
        Next j
    Next i
    rng3 = X3

    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With

End Sub
 
 
Random Solutions  
 
programming4us programming4us