Looping over data rows, but starting with the 5th row directly

So I am trying to automate a process in excel, but I run into a problem that I don’t know how to solve… When using the For Each Row in Data Table activity, I don’t know how to start the iteration from a certain row, like starting from the 5th row, It always starts from the beginning.

@maria-iulia.zdrenghea

if you want to start your process from the 5 th row

assign

newdatatable=inputdatatable.asenumerable.skip(4).copytodatatable

then above variable in for each row in datatable

cheers

Hi @maria-iulia.zdrenghea

Okay Inside For each row in datatable activity Insert the If condition and write the below condition.
Let’s call the datatable name as dtInput

- Condition -> dtInput.Rows.Count > 4

In then block insert the activities to move forward in automation.

The above condition will execute the activities after the 4th row means starts with 5th.

Hope it helps!!

And how should I write the condition if I want to be > Row1, which is an iterator from another for each row in data table activity

If you want to use an If condition in the loop, you would need to use the row’s index. Using the condition proposed, you would skip looping the table all together, if the table’s row count > 4.

By using solution proposed by @Shiva_Nikhil, you could use for example dt.Rows.IndexOf(row) to get the index of the Row1, or you can use Index property of the parent loop.

When we want to work on the same data table, but starting the loop from the X-th row we would use a for each activity (not a for each row…)

For each | item in YourDataTableVar.AsEnumerable().Skip(5)

  • do your work

We are doing so, as any CopyToDataTable would create a new DataTable and we will not work with / against our origin datatable

Same use another If condition and write the same condition but replace the 5 with 1.

Hope you understand!! @maria-iulia.zdrenghea

@maria-iulia.zdrenghea

can you explain more about what you are expecting

Sure, what I am trying to do is to create an automation in which I check 2 cells at a time if they have the same contents. So I use 2 for each row in data table activities, but I need the second for to start from the previous cell + 1 and I don’t know how to implement this.

@maria-iulia.zdrenghea

sorry
can you provide the sample inputs and the output so that i can help you




Screenshot 2023-08-31 140043

with above given approach it can be done

We do feel that a join / lookup logic is implemented with nested loops. If so we would recommend to tell us the over all goal as it has potential to get solved differently

@maria-iulia.zdrenghea

One approach for your requirment would be

  1. Loop 1 on dt1 and have a index variable created and assign it to the index property in for loop
  2. Now for second loop use dt2.AsEnumerable.Skip(index+1).CopyToDataTable

This starts the second loop from first loop row index plus 1

Cheers

You shouldn’t name your datatable variable “DataTable” because datatable is a datatype. Don’t name variables the same as reserved words like that. Give it a better name like myDT or customerDT or something that is meaningful and unique.

Also, don’t use Build Data Table after Read Range, it’ll blank out your datatable (I’m assuming you have used the same “DataTable” variable in Read Range and Build Data Table.

You don’t need to use Build Data Table if you’re doing Read Range - it builds the datatable for you.

Hi,

follow this steps:

  1. Read range

2.Assign subsetDataTable = YourDataTable.AsEnumerable().Skip(4).CopyToDataTable()

  1. For Each Row in Data Table
    use subsetDataTable in for each for start the iteration from 5th row