Combining "for each" and "if" statements

Hi there

I am trying to read row by row in a DT (excel data converted) and then check if the value of the cell contains something specific (circa 120 different scenarios). The read cell value can fall between 8 highlevel categories (corresponding to 8 different columns in final excel file) and underneath these different categories different scenarios can also exists (combined probably like 120 scenarios).

Hence, I’ve made a For Each on the DT, assigned a counter, read cell and then the various if statements.

After the For Each I then have a excel application scope where the assigned values from the if statements then are written to the cell in the final excel sheet. All seems ok, however there is something that does not seem completely working.

(1) Sometimes a row might contain information that needs to be assigned to several variables, however it seems like that as soon as one if statements becomes true then it ends the either for each - is that true? If yes, how to ensure that a For Each is not complete before the specific cell is checked for all combos?


You should be able to multiple If in sequence inside a ForEach iteration without triggering a Break or a Continue. It might help to see an example.

Without introducing too much programming, I’ll try to trade multiple If with an appropriate “data” structure. Maybe your case can be handled by using a second worksheet with at first column the expected values and the eight other columns with appropriate value or marker. The idea would be to Join (left join) your DT with this reference table and for each resulting row, iterate over the columns and do this if something in this column. Other approach would be to list in a reference table, the name of the process to apply to the row according found value and pass it the DataRow as argument.

Is each If statement independent or are you burying them in the else of the previous If statement? If each statement is independent without an Else then each one should be evaluated within your For Each Loop. It could be a data issue (i.e. hidden characters or spaces) or a logic issue so the True condition isn’t met.