Comparison of two datatable

Hello Everyone,

I have two different sheet of excel and I want compare the row value of one sheet with the column value of another sheet.

First sheet I’m having the values in row and in the second sheet I’m having the same values as column headers.

My use case is to compare these values and If I found the match I need to write some value in the corresponding cell.

Suggest me some options to get this done.

Thanks!

1 Like

Hi @Soundharya
Follow the following Steps

  • Read the data of Row Using Read row Activity it will be stored in IEnumerable collection.
  • Read the column data using Read Column Activity it will be stored in IEnumerable collection
  • Use for each To iterate data one by one and give the input to it the output of Read row.
  • Store the Values in Variable suppose Var1.
  • Inside for each Use Another For each To iterate Column Values and give the input to it the output of Read Column.
  • Stored The values in variable suppose Var2.
  • Use If condition in It And Give the condition As Var1=Var2.
    In the then Section Do what you want to do.
    Thanks & Regards

Hi @Soundharya

Use multiple Read range for both the sheets
Use multiple for each row loop
Check the condition as

Row(“column name”). ToString.equals(row(“column name”). ToString
Then use write cell activity
Thanks
Ashwin.S

There are lot of posts in the forum related to that @Soundharya,

Please check these

https://forum.uipath.com/search?q=compare%20two%20excels%20status%3Aclosed

https://forum.uipath.com/search?q=compare%20data%20tables%20status%3Aclosed

1 Like

Hi
Hope these steps would help you resolve this
—use a excel application scope and pass the file path first excel as input
—use a read range activity and get the output with a variable of type datatable named dt1
—use another excel application scope and pass the second file path as input
—use a read range activity and get the output with a variable of type datatable named dt2
—NOTE: if we have only excel but of different sheets then we can use two read range activity in a single excel application scope and name the second datatable variable named as dt2
—now use a for each row loop and pass the datatable variable dt1 as input
—inside the loop use a while loop and mention the condition like this
Counter < dt2.Columns.Count
Where counter is int32 variable of default value 0 defined in the variable panel
—no inside the while loop use a if condition like this
row(“yourcolumnname”).ToString.Contains(dt2.Columns(counter).Columnname.ToString)
—if this condition passes it will go to THEN part where we can include a assign activity to set a value to a cell we want (even with a write cell activity it’s possible)

Simple isn’t it
Hope this would help you
Kindly try this and let know for any queries or clarification
Cheers @Soundharya

Thanks you all for your suggestions… Solution helped me a lot!!!
Thanks @Palaniyappan

1 Like

No worries
@Soundharya

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