How to Compare and get change data

Hi guys.

I need help to solve this. i have 2 excel file like Old Data and New data both have common column. unique identifier is email id. now i want to find which row is change and get write in new data sheet2. upload below screenshot for your refence.

Thank you
Old data:

New data:

Hi @MD_Farhan1

Could you try the following Invoke code and let me know if it works:

LLM Generated Code. I’ve verified it as you can see below

INPUT:
Old.xlsx


New.xlsx

The WORKFLOW:

INVOKE CODE:
Code:

' Clone the structure of dtNew for output
dtChanges = dtNew.Clone()

' Loop through each row in the new data
For Each newRow As DataRow In dtNew.Rows
    Dim email As String = newRow("Email").ToString.Trim()
    
    ' Find matching row in old data
    Dim oldRow As DataRow = dtOld.AsEnumerable() _
        .FirstOrDefault(Function(r) r("Email").ToString.Trim() = email)

    ' If match found, compare columns
    If oldRow IsNot Nothing Then
        Dim isChanged As Boolean = False

        For Each col As DataColumn In dtNew.Columns
            If col.ColumnName <> "Email" Then
                Dim newVal As String = newRow(col.ColumnName).ToString.Trim()
                Dim oldVal As String = oldRow(col.ColumnName).ToString.Trim()

                If newVal <> oldVal Then
                    isChanged = True
                    Exit For
                End If
            End If
        Next

        If isChanged Then
            dtChanges.ImportRow(newRow)
        End If
    End If
Next

Argument:

Use Write Range to write the dt_Changed to Sheet2 of New.xlsx

OUTPUT:
The Output in Sheet2

If this solves your issue, Do mark it as a solution
Happy Automation :star_struck:

1 Like

Hi @MD_Farhan1

You can use a simple Query
dt_result = dt_input.AsEnumerable().Where(Function(x) Not dt_output.AsEnumerable().Any(Function(y) y.ItemArray.SequenceEqual(x.ItemArray))).CopyToDataTable()

I have tried with same inputs you have provided and it works
Output

Do mark it as solution if it helps :+1:

2 Likes

i got error. below attach my screen shot of error, variable and argument

Thank you

check the argument of Invoke code.

You have mentioned dt_Change not dt_Changes. Obviously it will give an error.

1 Like

Hi Farhan,

Please check the attached simple solution.

Forum2.zip (12.4 KB)

Here’s the output:

If it resolves for you. Please mark it as solution.

Happy Automation :slight_smile:

Pavan Kumar Gente

Thank you bro now working fine

1 Like