Compare Two excel and paste the 2nd excel matched data in 3rd excel

Hi Team,

I have 2 excel files-

1st excel file contains 5 column ( Name , Email , Phone No. , City , country)

2nd excel file contains 3 column ( Name , City , Company)

So, i want to compare the 1st excel Name and city value with 2nd excel Name and city.

If the value is matched then i want to paste the second excel matched data ( Name , City , Company) into the 3rd excel file

@Shivam_Rana

Welcome to the community

Please use join datatable activity after reading both the files data into datatable. Join to be done on Name and city(inner join)

then use filter datatable to have only columns needed that are second file related columns (Name,City,Company) then paste it into the excel using write range activity

cheers

1 Like

@Shivam_Rana
Follow these simple steps.

  1. Read First File by read Range and Store in DT_A
  2. Read Second File by read Range and Store in DT_B.
  3. Make new Datatable DT_C.
  4. Use assign activity and left side give DT_C and Right side DT_A.Clone
  5. use one more assign activity and place DT_C.
    Right Side

(From a In DT_A Join b In DT_B On a(“Name”).ToString.Trim Equals b(“Name”).ToString.Trim and a(“City”).ToString.Trim Equals b(“City”).ToString.TrimSelect DT_C.Rows.Add({b(“Name”),b(“City”),b(“Company”)})).CopyToDataTable

2 Likes

its working @Anil_G

one more question let suppose 1st file Name and City value is Raj and Delhi

and 2nd file Name and city value is lh_Raj and city Aa_Delhi.

how can i implemented this logic in our already created logic.

@Shivam_Rana

If you want to consider these as matched…then you cannot use join activity…instead need to use join via linq

cheers

if possible can you please share the linq query with me to achieve this ?

Thanks

@Shivam_Rana

Please check this

dt2.AsEnumerable.Where(function(x) dt1.AsEnumerable.Where(function(y) y("Name").ToString.Contains(x("Name").ToString) AndAlso y("City").ToString.Contains(x("City").ToString)).Count>0).CopyToDataTable

This compared if dt2 has Name and dt1 has LH_Name …if it is other way rounf then interchange x and y in the contains statement

And gets the dt2 records which are matched

cheers

1 Like


i have implemented your logic but it is showing me the error.
Please help

@Shivam_Rana

Please paste everything in a single line

cheers

it worked :grin:

you are great @Anil_G :smiley:

cheers

1 Like

@Shivam_Rana

Happy Automation :slight_smile:

Cheers

Done :smiley::ok_hand:t2:

Thanks

1 Like

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