How to loop through specific number of rows

Hi everyone, I have like 400 rows to read in excel, i want to read only 4 rows per iteration and write it on another sheet. How do i use for loop to read 4 rows per iteration? Also excel contains 8 columns so yes i want to read 4 complete rows per iteration till 400 rows.
Plz help
Thanks in advance

Hi @Daniyal_Tahir .

Please try this,

  1. Install this package
  1. Read the excel sheet data in the datatable variable name dt.

  2. Create a variable called counter, type - int default value - 0. And another variable called dt2 (type - datatable), default value - new datatable

  3. Use a do while loop and in condition give counter <= dt rows.count

Inside the body of the do while loop

  1. Drag the activity called Select Custom N Rows(it will come within the package we installed earlier), and set input as dt, starting row as counter, ending row as counter + 4, output as dt2.

  2. Use write range activity and write the datatable dt2 to the new sheet (Sheet name can be “Sheet” + counter.tostring

  3. Use an assign and give
    counter = counter + 5

Thanks

Hi,

Hope the following helps you.

Sequence2.xaml (8.5 KB)

Note: If the number of rows is not divisible by 4, additional process is required.

Regards,

Hello,


Copy4Rows.xaml (8.5 KB)

I tried to make it as simple as possible, hope this helps.

Best,
Charbel

Thanks @prasath_S it worked its pasting all the values…but at the end its giving an error “No value found in row413”

@Charbel1 its giving an error “This row already belong to another excel” on Add Data Row activity.

@Daniyal_Tahir please give this a try,

  1. Put the activity select custom n row into a try catch or give continue on error true.

Or

  1. Put the activity select custom n row inside an If activity and in condition give counter <= dt.rows.count

In then part put the activity and in ending row property give counter + 4.

In else part put the same activity and change the ending row as dt rows.count

Think the first one will work.

Thanks

Take a look at this solution.

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