Loop through columns and identify data in each cell

Hi,

I want to loop through the columns D to n number of columns. And the data will present only 4 columns of each excel. I want to check which column is having the data and fetch that data along with the header. I want to loop through each row as well. How can I do this? Can anyone help me on this please? I will attach the column format.

Thanks in advance!

Kind Regards,
Renju

You can read the third cell or fourth of each column using a for each loop till the number of columns on excel. (You will get number of columns reading the excel using read range and the column count as datatable.columns.count), then you can find which column has values and store those four column numbers in an array.

Then you can loop through the data table using that particular column numbers as row(column number).ToString

Hi @HareeshMR,

Thanks for your quick reply!

How can I loop through each column in an excel sheet starting from 4th column to n number of columns?

Kind Regards,
Regards

You need to use for each loop for that as below

image

To skip it till the forth item, you need to use the index (output of for each activity) like, if the index is greater than 3, then flow to THEN condition

Hi @HareeshMR,

I tried the way you suggested. Could you please suggest me how can I read each cell values. I know we can use String.IsNullOrEmpty to check the cell is having value or not. But I don’t know how to read each cell value. Normally we use rows.Item(0).ToString. I tried to change the parameter rows.Item(index_variable).ToString with index variable. But I’m getting error. How can I read values in each cell column by column for each row?

Regards,
Renju

Sorry, that was my mistake.

Use for each row and increment the values in the row(0).tostring that will read the column value of that row based the index. Try this way and let me know if that helps

1 Like

helped a lot
thx

1 Like