Find difference between 2 Sheets - put difference in 3d sheet

Hey guys,
I’ve got 3 heavy tables of 150x1300 cells. Table1, Table2, Table3. They look the same.
I need to check if any cell of Table1 differs from the same cell in Table2, then put the difference in the same cell in Table3.
How should I do this with the maximum performance?

You can do it with VBA code quite easily.

Option Explicit

Sub CompareWorksheets()

    Dim varSheetA As Variant
    Dim varSheetB As Variant
    Dim strRangeToCheck As String
    Dim iRow As Long
    Dim iCol As Long

    strRangeToCheck = "A1:B4"
    ' If you know the data will only be in a smaller range, reduce the size of the ranges above.
    Debug.Print Now
    varSheetA = Worksheets("Sheet1").Range(strRangeToCheck)
    varSheetB = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.
    Debug.Print Now

    For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
        For iCol = LBound(varSheetA, 2) To UBound(varSheetA, 2)
            If varSheetA(iRow, iCol) = varSheetB(iRow, iCol) Then
                ' Cells are identical.
                ' Do nothing.
                ' Cells are different.
                ' Code goes here for whatever it is you want to do.
                MsgBox "Cells are different, do something"
            End If
        Next iCol
    Next iRow

End Sub
1 Like

Thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.