Help with how to use contains in two different excel

Hi everyone,

I need help for my problem. I need to compare data in two different excel and write the data the first excel with not exist in the second excel. I already saw the post How to compare rows in two different excel and already tried to adapt for my case but I receved the error “table doesn´t have a primary key”, someone can help me? in resume i need:

read the first excel
read the second excel
validate if the information in first excel already exists in second excel
if not exist the data are different should be write in a new excel

pls see my test in attach.

Thanks, (18.2 KB)

I see you are trying to use a Do While loop. Have you considered a For Each Row?
Basically, you can run a For Each Row of the first datatable, then use another For Each Row inside that For loop for the second datatable. Then, use your If condition to see if the data matches.

For Each row1 in dt1
–For Each row2 in dt2
----If row2.Item(columnIndex).ToString<>row1.Item(columnIndex)

However, if you have many rows this solution isn’t very fast.
Another option you may look at is LINQ functions, mainly the .Select() function. This will let you filter the second datatable instantly down to the matched row

For Each row in dt1
–Assign array[datarow] type variable = dt2.Select("[columnheader1] = "+row.Item(“columnheader1”).ToString and "[columnheader2] = "+row.Item(“columnheader2”).ToString)
–If arrayofrowsVariable.Length > 0

Hope this helps!


EDIT: Oops, you can also utilize .Contains when finding the match.

Check this one as well

Hi @vvaidya and @ClaytonM
sorry my delay I’ve had a lot of work in this days to set up one workflow with uipath. But now I finished all :slight_smile: @ClaytonM I tried to use your solution but I received some errors so I used the solution gives of @vvaidya. But not your fault off course, I must have used something wrong :slight_smile: @vvaidya you already save me 2 times, thanks a lot.

1 Like