Replace empty rows in a datatable with a given value

I have data in a data table which contains empty rows too and I want to loop through the table.
I noticed that foreach will not count the empty rows, so it doesn’t go until the last row.
So if the table has 10 records and 4 of them are empty, foreach will stop at the 6th row.

It would be easy to use a filter to delete all empty rows, however the position of data (row number) is important so I need to keep it that way.

Therefore, I would like to replace all the empty rows with a string (say, “Empty row”), so that foreach will count these rows too.

Is there a more elegant solution than using while with a counter starting from rows number and going to zero?

If those rows are not coming in your data table then you cannot do anything…
Check the datatable count before for each…
If those are there then it means for each will also loop them…

You can use set value
Main.xaml (9.2 KB)

You are using foreach, that is the problem I have, so it’s not a solution.
The datatable empty rows should be fixed BEFORE using foreach.

Empty rows are counted and showing for example in Output Data Table.
It’s only the foreach that ignores them automatically.

Don’t check with the output data table…Check exact count using varDt.row.count method…

If you can share the workflow and file for more investigation…

Yes, when I check with count it counts only non-empty rows. So although datatable has 10 rows (shown correctly in output data table), the count shows 6 rows.
How can I fix this stupidity?

Hi @ranger
If it’s always a delimited number of records known before (let’s say X), you could use Read Cell activity in a while loop until the counter gets to the X value, and write cell activity with what you need if it’s empty.
Then you can keep going with read range activity

It is not possible if count is showing less and in output data table showing the else data…If it is not in data table then it should not be in the output data table…

share sample screenshots which will explain issue…

we might need that excel to see if there is really issue with activity…

I send the test files, please check.
I need the data D4:D13 in data table and to loop through all of the 10 rows, but it can see only 5 rows!

test.zip (803.6 KB)

You are using the UiPath Pro studio so I can’t open your workflow however I tried your file and I can see all empty and not empty rows…

Check if you are using the same activities and range in reading range activity…