Compare two values from two sheets

I have 1 excel file with 3 sheets in it. Im only using 2 of them in my assignment.

I want to write range a cell in sheet1 IF the column1 value is the SAME as in sheet 2.


sheet1 - column1 - value: 222
sheet2 - column1 - value: 222

If both sheet values are EQUAL then write range in sheet1 "it is equal"

And continue doing this for each item

Sample flow i have created for comparing values from two different sheet. ExcelFile2.xlsx (8.8 KB)
ExcelFile1.xlsx (9.4 KB)
Main2.xaml (11.0 KB)

I dont quite understand the rowIndex part… can u explain that to me please.

@Ibra rowIndex = dT1.Rows.IndexOf(row) + 2

dT1 = DataTable Name
Rows.IndexOf(row) = Index number of the row for which we are processing the row
+ 2 = If you are reading the header your index will be 0 so you have to add 2 that’s why we used +2

we use rowIndex variable because we have to write the “Match” status in front of the same row for which we are processing.

It’s not like using only dt.rows.indexOf(row) you can use any counter variable like i and increase the counter one by one.

I get an error that says that it cannot find the columnName from my dt1… trying to figure out whats the problem.
FIXED: forgot to add the headers.

Now its working fine correct ?

Nothing happens.

Is it maybe because i have column names in sheet1 but not in sheet2?

Yea column name should be there because through column name only we are comparing the values.

I have a write cell that doesnt have a “add headers” option anywhere. Whats the best solution? Change to write range?

@Ibra you can use write cell Activity for Adding headers for example


This didnt work me me.msg

EDIT: Fixed by adding 2 more write cells that only servers as headers.

Thank you!

What ever you are trying in A1 cell is that is your header name ?

Because header name should always be same but i can see you are using variable.

If you can bit elaborate your problem so that i can explain you in one shot.

All i need was just headers to fix my problem. The solution was adding headers with ‘Write Cell’ activity and place the range at A1 and B1 (the second headername).

When thats done - i added my values with a ‘Write Cell’’ again but with A2 and B2 range.

For optimization reason: is there a BETTER way to add headers to an excel file or is it OK what i just did?

It’s probably ok.
Other methods would be:

—to use a data table. Use the Build Data Table activity and set up your headers there, then to assign the values, use the Add Data Row activity using the Array property like {clientInformations, ArrayOfID(1)}. Then, when the the table is complete you can simply use Write Range to overwrite the spreadsheet with the data.

—use comma-delimitted text then use Write Text File using a .CSV extension. To get data table just use Read CSV after you are created the csv file.

Ok thank you! :slight_smile: