Check if string from datatable1 contains in datatable2

Hi Everyone,

I have two excel files. In first excel i have a sample list of companies which i want to check in the second excel file. If row matches any string in second excel file keep that row otherwise remove.

Any help would be appreciated.
Here is my code: File_Check.xaml (8.1 KB)

Hi @zeshanm9,

If possible can you share those two excel. (69.1 KB)
@shivagowdavarad there are the excel files

Hi @zeshanm9,

After 2 read range, let’s say,
Dt1 —> is your main datatable.
Dt2 —> is datatable where, you search for matching value.
use following linq code in assign activity

MatchedDT =

Dt1.AsEnumerable().Where(Function(row)  Dt2.AsEnumerable().
Select(Function(f) f("CompColumnDt2").ToString).Any(Function(x) x.Contains(row("CompColumnDt1").ToString))).CopyToDataTable()

MatchedDT —> will hold records of Dt1 which have matching value in Dt2.

Note - Make sure you put your column names in code.
you can check the MatchedDT by using write range.

1 Like

Hi @samir,

Thank you for the solution. If my column don’t have any name so can i use “Column0” or not?
I tried your solution but i am not getting the required result. Can you please check my code and excel files and send me the code after your update if required.

@samir (108.5 KB)
please find the code and excel files with output. I am getting all the results in the output but i want only the matched ones


After seeing your files get the exact idea, here’s the code,

Dt1.AsEnumerable().Where(Function(row)  Dt2.AsEnumerable().
Select(Function(f) f("CompNameDt2").ToString).Any(Function(x) row("CompNameDt1").ToString.Contains(x))).CopyToDataTable()

here’s my sample workflow for your better understanding —> Main.xaml (9.3 KB)

Note - In your files type is llc but in data there’s LLC, so clearly llc & LLC doesn’t match, So you’ve to handle this in your example.

@samir sorry i was not able to understand the example you shared. I need to read from excel files not to build it. And if any value does not matched then it should not write those value but now it is writing all the values. Can you please check my code i have shared above also attached (108.5 KB) “” and advise.


After read range its gonna end up in datatable only.

Dt1- image Dt2 - image
Output —> image
here you can see that value with LLC & INC are there in output because its there in Dt2, but Compy 123, Pvt LMT doesn’t match the condition, why, its because there’s lmt which doesn’t match LMT

I have checked your files buddy there’s value inc. in one file and INC. in another… so it’s not gonna match…
If you provide your expected output file then it’ll be easy for everyone here to suggest.

Sure. This is my current output.

and my expected output is(in this case i make llc to LLC in the excel sheet so the output should be like this) :

I can confirm some issues as I prototyped the same from your older, forked, duplicated Topic ( Compare two Excel Sheets using Linq )
and got also some rows into the result which should be blocked. The initial analysis did not find out the issue. I started to remove empty columns for the filtering, but didn’t solved it. Some unkown, hidden parts are doing a filter confusion.

But we will sort it out

Here’s the workflow —> (85.4 KB)
See I’ve added LLC & INC in master file…

Here’s the output —>

by using this only I’ve get the expected output.

Thank you @samir it is working now. Appreciated.

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