but as automatically as possible, because let’s say in the “crop” column it changes to organic lucuma and so I want it to detect in the other excel what is the code to register
My goal is to detect the code you have to write and register it in Excel
if, for example, I read the first excel with “read range” then I pass it through a “for each row” and with “get row item” I extract the value from the “crop” column then I put it in a “if” condition
then with what is written in the column “crop” I must detect its code that is in another excel, but I want to make it dynamic since if it changes the value in the column “crop” I can detect which is its correct code
Hi @borismh I am also struggling a little bit to understand which part you are struggling with. I will do my best to guess so please correct me if I am wrong. You want to read the excel worksheet containing all the data, iterate through each row in the data and read the value in the “Cultivo” column. Then you want to use that value to lookup the corresponding value from the lookup table found in the 2nd worksheet. I’m not sure what you’re doing with this value but i’ll assume you are writing it back to the original excel.
Based on your example you see the value is “Cacao Organico” in the “Cultivo” column, so you use the lookup to determine the value is “ESA201902” which you will then put back into the same line (i’ll put it in the “Comentarios” column)
I would do the following:
Read range for the whole data worksheet to save it as a datatable i’ll call dt1
Read range for the whole lookup table worksheet to save it as a datatable I’ll call LookupTable. Since your worksheet doesn’t appear to have headers, be sure to leave the ‘Add headers’ property unchecked
For each row in dt1
a. Assign LookupValue (this is a string variable) = row.item(“Cultivo”).ToString
b. Assign ReturnedValue (this is string variable) = LookupTable.Select(“[Column1] = '” + LookupValue + “'”).FirstOrDefault().item(“Column2”).ToString
c. Assign row.item(“Comentarios”) = ReturnedValue
The above code would result in the correct value being put into the “Comentarios” column for each row of your input data worksheet
Also, you can change any of the column names. Just be sure to check the ‘add headers’ property in step 2 which indicates your data has headers. Then in step 3b change it to: