Create new datatable based on criteria


I know there is various topics regarding this, but I can’t find the solution that helps me.

I get an excel file that I need to sort out certain rows from and create a new excel file which will go to manual control. I have solved this by first creating a data table and several If statements to control if data in the row is going to manual control or not.

My issue is that I don’t get the robot to “paste” the entire row that is going to manual control into a new data table and further an excel workbook. All of the rows going to “Else” have to go into a new workbook to manual control.


Can you share the condition and what is your requirement.


If by “paste row into a new data table” you mean adding it to another data table, be advise that you cannot have a DataRow object contained by 2 DataTable objects. You have to create a new DataRow object to add it to the second data DataTable (or use Add Data Row activity and set the field values in the ArrayRow property).

Yes, it means adding it to another data table.

So I need to create a new DataRow, and how could this be done for each of the rows not matching my conditions?

It would be like:


Then the condition should be variabl.Contains(“word”) and in the else block (you said you want to keep the items not matching the condition) add an AddDataRow activity with ArrayRow property set to {row(0), row(1), row(2) …} (this will create a new DataRow object in the second data table).

1 Like

Will this go into a new datatable that i could further create into a excel sheet?

Yes, it can be used in a WriteRange activity.

Do i first use the Build data table activity?

It looks like the new table only get one row, and it does not add more to the table. Any suggestion?

Create DataTable object (with Build data table activity) outside the loop. In the loop just check for condition and add row in the new DataTable object.

1 Like

This solved the problem :slight_smile: Thanks!!

You can also do like this
If you want to copy the Datarows from one Datatable to another you can also use Import row method.

Dt1 is your present datatable

Then Run for each row for Dt1
Inside use Invoke Method
And use import row method, pass the row as argument.