For each row in excel, capture the first row, then the following row's cells

Hi. I’m currently working on automating a use case wherein I need to capture a set of data from an excel file (newDT), but every time I loop (in my for each row activity - see Figure 1.B below), it just captures the first row’s data, so basically it loops twice (because there’s 2 rows on my excel file) but on the second loop I want it to capture the second row (it still captures the first row’s details on the second loop)
So here’s what I have so far;

My excel looks like this:
Figure 1.A - newDT

My for each row looks like this:

Figure 1.B
image
1/2

Figure 2.B
image
2/2

I was thinking of having a counter but I don’t know how to implement it on .NET row command (if that’s even possible via .NET code)

Any suggestions on how I can work this around?

Regards,
Mc

2 Likes

Hi @UiP_Mc

Inside for each loop you can give this condition for iteration,

For each :row in newDT:
{
Type into: row(“Item_Description”).ToString
}

It’ll iterate by Item_Description element

Thanks,
Goutham Vijay

1 Like

In the Type Into, use:
row(“Item_Quantity”).ToString

2 Likes

Hi guys. So that means I just need to modify the typeInto from
newDT.Rows(0)(“Item_Quantity”).ToString
to
row(“Item_Quantity”).ToString?

I’ll try this. Thanks guys! :smiley:

2 Likes

Yep. Right :slight_smile:

1 Like

@UiP_Mc
Buddy the reason why you get this error when we are iterating a datatable with for each row loop, to get the value of each row in a particular column we must mention the foreach row loop variable and not the datatable(unless we need in specific)
So as you have mentioned as newDT.Rows(0)(“Item_Quantity”).ToString, though you iterate through each row, it will only take the value of first row (index 0) as per this.
Instead if you have mention as row(for each row loop variable) which gives us differnt value as it iterates through each row we wont get the repeatd value as you get now.

Thats the reason buddy

hope this would help you

Cheers

1 Like

Thanks for this, it makes a lot more sense! (Sorry I’m just recently learning both UiPath and .NET :smile:)

1 Like

Cheers buddy

Keep going

1 Like

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