Is it possible to remove part of rows from DataTable? using start and end row index?

I have an Excel sheet, and using Read Range, I get a DataTable object (dt_All), and this has 3 different parts, each of which needs to be processed differently. The 3 parts are separated by an empty row like:


As you can see each section has completely different structures, so they need to be processed differently, but I am reading this whole table at once, so I can separate them later. This way, I don’t need to use Read Range 3 separate times.

I created a logic that returns an array of Int32 (arrEmptyRows), containing the row index of where the empty rows exist. In the above example, the returned array will be like {6, 11} because these are the empty rows.

Now, using arrEmptyRows, I want to retrieve each section from dt_All. How can I do this? Like first, I want to chop off any rows after arrEmptyRows(0) so I can only get the DataTable object of the first section.
Then, after I finish processing the first portion, I can now chop off rows before arrEmptyRows(0) AND rows after arrEmptyRows(1), because that will produce the second section of dt_All.

Is this possible?

hello @tomato25

if you know the range of indexsof the Row then you use the below expression to process each of the row based on the separation

DataRow = DatatableDt.row(indexofTheRow) ///Return the data row

then you can add this row to a new table (build data table)

i hope it will work for you


1 Like

See below:

  1. Build Datatable for each section
  2. Main Logic per section:

Section1Index = arrEmptyRows(0);

While( NOT String.IsNullOrEmpty(ParentDatatble.Rows(Section1Index+1)(0).ToString))
Add Datarow on the Datatable per section;
Section1Index = Section1Index + 1;

*NOT String.IsNullOrEmpty(ParentDatatble.Rows(Section1Index+1)(0).ToString) - checks if next row is not empty

*It will stop adding datarow once it reaches an empty row
*Apply it to all section

1 Like

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