Compare two spreadsheet

Hello Expertise

Is there any way how the whole spreadsheet data can be compare with other spreadsheets.
Thank you

Hi @James90

Can you mention the range for read range activity based on row(“column name”).ToString.Equals(row(“Column Name”).ToString

Thanks
Ashwin S

2 Likes

You can use a simple macro to do this:

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.
                
            Else
                ' 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