How to stop reading rows once an empty one is encountered

Hi all,
I am trying to read this excel file, reading only the rows with data.

I made the read range only to start reading from D26 as that’s where I need it to start from.

How do I get the process to stop reading once it has reached the end? Right now it will continuously read all the empty rows infinitely.

Thanks!

Hi @SRoyi

Use the read range workbook activity to read the excel. In the cell field give the required range that want to read.
D26:L

Hope it helps!!

loop to go through each row of the data and check if it’s empty or not. For this, you can use the “For Each Row” activity, Inside the “For Each Row” activity, use an “If” condition to check if the current row has data or not. You can do this by using the “IsNullOrEmpty” function on the first column of the current row. If the row is empty, you can exit the loop.
In the “If” activity, use the condition String.IsNullOrEmpty(row("ColumnD").ToString) .

@SRoyi

  1. Use Read Range to read the data from D26 onwards into a DataTable variable (let’s call it ‘dtData’).
  2. Use a For Each Row loop to iterate through the rows in ‘dtData’.
  3. Inside the loop, use an If activity to check if the row contains data.
    Condition: Not (String.IsNullOrEmpty(String.Join(“”, row.ItemArray)))
  4. If the row contains data, process the data as needed.
  5. If the row is empty, use a Break activity to exit the loop.

Hi, right now the robot takes wayyyy too long to read the data from D26 as there are thousands of rows in this excel, is there another way to approach it?

@SRoyi

Read Range with Defined Range : Instead of reading the entire worksheet, specify a smaller range that covers only the rows you need to read. If you know the last row with data (e.g., D5000), use the “Read Range” activity with the range “D26:D5000” to read only the relevant data.

or

  1. Use Read Range to read the data from D26 onwards into a DataTable variable (let’s call it ‘dtData’).

  2. Use an Assign activity to filter the DataTable based on non-empty rows:
    Assign activity: dtFilteredData
    To: dtData.AsEnumerable().Where(Function(row) Not (String.IsNullOrEmpty(String.Join(“”, row.ItemArray)))).CopyToDataTable()

  3. Now you have the filtered data in the ‘dtFilteredData’ DataTable variable. You can use this DataTable for further processing.

1 Like

Ahhh I see, thanks for the help!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.