How to compare two data table row by row, column by column and cell by cell and update the cell value if it is not matched.Give the solution using invoke code

Requirement:
1.suppose dt1 and dt2 are two data table.
2.check dt1 uniq cloumn value is present in dt2 uniq column value.
3.if present then compare dt1 column cell value and dt2 column cell value using uniq key.
3.if dt1 column cell value is not equal to dt2 column cell value then update the dt1 column cell value to dt2 column cell value.
4.if not present the insert the dt1 column cell value to dt2 column cell value.
Note:
give the solution using invoke code.

@debasisa
can you share with us some sample data excel. This allows us faster to work out a solution approach. Thanks

1 Like

Hi, what do you have so far? We can help where you are in trouble :slight_smile:

This will compare two excel sheets. You could adapt it for two files:

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

thanks for your response.but i have two data table.i need compare two data table that i have mention in my requirement.i need the solution for invoke code.

example:
dt1:
id name mobile
1 deb 567
2 ram 456
3 sam 687
dt2:
id name mobile
1 deba 5679
2 ram 1456
Result should be
dt3:
id name mobile
1 deb 567
2 ram 456
3 sam 687
Note:
compare two table using invoke code activity.
id is uniq key.
compare dt1 with dt2.
if any value mismatched in dt2 then change the value in dt2(respective value in dt1).
if new row available in dt1 then insert the row value in dt2(respective column value.

What have you tried so far? This may be better posting on a stack overflow forum as you are asking for a solution in code. Which code would you like? C#, Python, VBA?