# While loop excel

**URL:** <https://forum.uipath.com/t/while-loop-excel/737479>\
**Category:** Activities\
**Tags:** studio, excel, uiautomation, activities\
**Created:** [April 28, 2024, 10:48am UTC](https://forum.uipath.com/t/while-loop-excel/737479 "2024-04-28T10:48:33Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 28, 2024, 10:48am UTC](https://forum.uipath.com/t/while-loop-excel/737479/1 "2024-04-28T10:48:33Z")

</div>

hello guys please help😭

so i have to automate a process where i have to take information from excel sheet and put it into a website form.

but here’s the problem, the form can only submit 4 companies at once meaning it can only extract the first 4 rows of information in excel, but i have more than 4 rows/companies that i need to submit

how can i automate the process in a way i can submit the next 4 rows after the first 4 rows until excel has an empty row?

i need to be able to submit the next 4 or less than equals to 4 companies after the first 4 companies. how do i create this process

thanks

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [April 28, 2024, 11:50am UTC](https://forum.uipath.com/t/while-loop-excel/737479/2 "2024-04-28T11:50:45Z")

</div>

@meenyi

`Dt.AsEnumerable.chunks(4)`

Use the above as input argument to for loop and till the items are completed the loop would run giving 4 or less items each time till the items complete

Cheers

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [April 28, 2024, 11:52am UTC](https://forum.uipath.com/t/while-loop-excel/737479/3 "2024-04-28T11:52:12Z")

</div>

@meenyi,

You will have to get this by reading the excel file into datatable and splitting it’s rows into chunks of 4. Here is sample solution.

**For Each activity** `Argument Type = Int32``List of items`

```auto
Enumerable.Range(0,Cint(Math.Ceiling(dt1.RowCount/intChunkSize))).ToArray

```

 ![image](https://global.discourse-cdn.com/uipath/original/4X/9/2/9/9292ea00620eba0f646d12dcec1ca08e7ee17b57.png)

**Get Chunk of DataTable:**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/0/d/c/0dcc984e42f5b3c369e7002484f3d6e18c677514.png)

**Full Solution:**

 ![image](https://global.discourse-cdn.com/uipath/original/4X/3/8/2/382051144c1b250f5c8fba54357a8411ec536954.png)

**Sample Code:**

[Data.xlsx](https://forum.uipath.com/uploads/short-url/yOf9q0ug0xU1lBAQ4FtuIJqx869.xlsx) (11.3 KB)  
[Workflow.xaml](https://forum.uipath.com/uploads/short-url/dqEst5CqqOsz4HlWXNG864tYpnX.xaml) (10.1 KB)

**Output:**  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/4/c/4/4c41b027463697c2cfc27547d753d56386abf06f.png)

You can add your logic to enter these 4 rows into form as per your requirement in For Each loop.

Don’t forget to mark my answer as solution. 😃

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 28, 2024, 12:05pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/4 "2024-04-28T12:05:19Z")

</div>

hi where do i input this at?

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 28, 2024, 12:08pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/5 "2024-04-28T12:08:44Z")

</div>

hi! will this process allow me to submit the next 4 or less companies inside the form?

thanks

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [April 28, 2024, 12:09pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/6 "2024-04-28T12:09:55Z")

</div>

@meenyi

this si how it looks

 ![image](https://global.discourse-cdn.com/uipath/original/4X/0/9/4/094c9d2d55fe3bf6cb30ff17bf46f7d5c4288b36.png)

currentitem.copytodatatable is the table contianing your required rows…for each iteration those would change

cheers

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [April 28, 2024, 2:53pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/7 "2024-04-28T14:53:33Z")

</div>

@meenyi

Yes! It will do that.

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 28, 2024, 4:52pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/8 "2024-04-28T16:52:57Z")

</div>

may i know what is the log message, output data table and log message inside the body for?

thanks

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 28, 2024, 11:14pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/9 "2024-04-28T23:14:47Z")

</div>

hi! it is not working😭 it doesn’t just submit the first 4

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 28, 2024, 11:18pm UTC](https://forum.uipath.com/t/while-loop-excel/737479/10 "2024-04-28T23:18:18Z")

</div>

hi this doesn’t work😭 it does not only key in 4 entries

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [April 29, 2024, 2:56am UTC](https://forum.uipath.com/t/while-loop-excel/737479/11 "2024-04-29T02:56:15Z")

</div>

@meenyi,

Hey it’s just to print the 4 rows picked in the current iteration. It was for demo purpose only. You can remove it and add your logic to fill your form.

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [April 29, 2024, 3:08am UTC](https://forum.uipath.com/t/while-loop-excel/737479/12 "2024-04-29T03:08:56Z")

</div>

@meenyi

Then the flow you are doing inside this loop is wrong may be…the ask was for getting 4 rows each…inside that no detaila are given…

Can you please show what are you doing and what failed…that would help than not working

Cheers

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 29, 2024, 3:26am UTC](https://forum.uipath.com/t/while-loop-excel/737479/13 "2024-04-29T03:26:22Z")

</div>

hii my apologies, because it’s confidential information hence i’m unable to show u how is it like. but allow me to breakdown…

basically in a website for me to submit forms, i can only submit 4 companies at once as its a limit from the website.

however, the excel that i read these companies information from has more than 4 rows,

how do i make the process such that im able to submit the first 4 companies and still followed by the next 4 companies until they finish submitting all companies.

for example if i have in a total of 14 rows, how can it submit 4 at once then the next 4 then the next 4 then the remaining 2?

hope this is clearer

thanks

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [April 29, 2024, 3:32am UTC](https://forum.uipath.com/t/while-loop-excel/737479/14 "2024-04-29T03:32:22Z")

</div>

@meenyi

This explanation is understood and the idea given above is for splitting into those chunks only…when you say not working what is happening?

When you say submit 4 in chunks…how are you doing it? Did you first happen to check the loop and see if 4 items are coming pr not?Did you understand that first? Did you find a solution on how and what to write inside loop?

Cheers

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 29, 2024, 3:53am UTC](https://forum.uipath.com/t/while-loop-excel/737479/15 "2024-04-29T03:53:41Z")

</div>

hi i tried another method by using while loop  
but it still doesn’t works😅, please help if possible

 ![IMG_2837](https://global.discourse-cdn.com/uipath/original/4X/9/c/2/9c26f106723ac59960d7e60a35ebe5777d958309.jpeg)

for example my excel has 6 rows in total but 1 row is the header so means there are 5 rows of information.

i’ve set the rowCount to Int32 default:0 and totalRows to Int32 default:6

however it is still capturing the 5 row items

thanks

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [April 29, 2024, 4:42am UTC](https://forum.uipath.com/t/while-loop-excel/737479/16 "2024-04-29T04:42:15Z")

</div>

@meenyi

Please use a for loop as mentioned above that would be straight…

Because ai believe…you are checking all conditions but in the for each row in datatable you are still passing full datatable so it is looping whole…that is where for loop with currentitem.CopyToDatatable will help

Cheers

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 29, 2024, 6:08am UTC](https://forum.uipath.com/t/while-loop-excel/737479/17 "2024-04-29T06:08:09Z")

</div>

hi are you referring to this?

 ![IMG_2839](https://global.discourse-cdn.com/uipath/original/4X/8/9/b/89ba84331ceea829c1661fac51d9cf485f3e228b.jpeg)

does it mean i used for each instead of while?

and currentItem.copytodatatable do i need to change anything or this is it?

---

<div class="post-metadata">

**Author:** ![meenyi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/meenyi/32/423315_2.png) [@meenyi](https://forum.uipath.com/u/meenyi)\
**Post date:** [April 29, 2024, 6:10am UTC](https://forum.uipath.com/t/while-loop-excel/737479/18 "2024-04-29T06:10:25Z")

</div>

hi thanks! however it’s still reading the rest of the rows, not just the first 4 rows

thanks

---

<div class="post-metadata">

**Author:** ![ashokkarale](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashokkarale/32/474400_2.png) [@ashokkarale](https://forum.uipath.com/u/ashokkarale)\
**Post date:** [April 29, 2024, 6:30am UTC](https://forum.uipath.com/t/while-loop-excel/737479/19 "2024-04-29T06:30:06Z")

</div>

@meenyi,

If you need only the second chunk. here is the updated solution.

 ![image](https://global.discourse-cdn.com/uipath/original/4X/c/d/3/cd3b2bfbb07ae02b5c8d3992723a45cffee3761f.png)

**Output:**  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/0/a/e/0aeec6f9dbdf2b60e5bccc7e180bff677b1ab0c0.png)

Sample Code:  
[Workflow.xaml](https://forum.uipath.com/uploads/short-url/vC4GjnebbSjPenuuTi6PYo43qUg.xaml) (11.4 KB)

Thanks,  
Ashok 🙂

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [April 29, 2024, 9:35am UTC](https://forum.uipath.com/t/while-loop-excel/737479/20 "2024-04-29T09:35:16Z")

</div>

@meenyi

yes that is what you need to use inside the if condition and the for loop datatable inside it

cheers

[Next page](https://forum.uipath.com/t/while-loop-excel/737479.md?page=2)
