Showing results for 
Search instead for 
Did you mean: 
Helper IV
Helper IV

any substitute for for each loop in desktop flow

like i want to substitute the for each loop because it taking time any substitite for that

Super User
Super User

You can just do a loop, so you can dictate the beginning and end. 

for example, if I had a spreadsheet and it had 1000 rows, but I only want to process row 2-100.


Launch Excel

Set variable %LoopMax% to 100

Loop starting at 2 to %LoopMax% interval of 1

’Now %LoopIndex% will always be the row I am on


Same goes with Files:


Get Files

Loop 0 to 99 increment of 1

‘ The current file is always %Files[LoopIndex]%

can we use java script for this to run more faster what u think?

Super User
Super User

Just did a test, by reading a spreadsheet with 1000 rows.
Did a loop using FOR EACH and a normal LOOP, in those two loops I converted each row to numbers.
Both loop's took exactly 47 seconds (running from within PAD)

can u try this with Run Java Script

Could you be more specific?
My knowdledge about Java is limited.....😊

like we applying loop in drag and drop can we do this manually in java scripts i think it will do more faster i never tried but i need suggestion and implementation and my knowledge in js is very limited😅

Hmmm then you would have to do all your scripting in Java - I think.
What are you trying to do inside the loop?

nope i just finding alternative of for each loop

Can't see what's wrong with using Loop or For each, it's more likely what you are doing inside your loop that slows you down.

like if i have 10000 records it will take more and more time for reducing time that why i need a suggestion that if we apply same in java script then what will happen

Well I don't know what you are doing to your records in your loop, but we handle excel sheets with more than 20.000+ rows where each row has to be taken care of, and it does not take that long, when it runs unattended on our servers.


But I wish you all the best in your search, and please let me know if you find another way to do it - always eager to learn.

Super User
Super User

Hi @dheeraj867 


Can you elaborate the complete requirements what are you trying to achieve using javascript and loops, in which application (Excel?), and what exactly in that application?


Power Automate 22-02-2022 23_05_46.png

Power Automate 22-02-2022 23_05_54.png

Power Automate 22-02-2022 23_06_01.png

  i want to optimize this using java script

Super User
Super User

Loop using javascript for interacting with Excel.


Make sure to change Excel path and remember to give double slash \\ as shown below.


Customise as per you requirements.




var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("C:\\test\\LoopExcelJavascript.xlsx");
excel.visible = true;
var excel_sheet = excel.Worksheets("Sheet1");
var data="";
var col=1;
var i;

for (i=2; i<=6;i++)
 data = excel_sheet.Cells(i,1).Value;
data = data.substring(3);
 excel_sheet.Cells(i,1).Value = data;



Helpful resources



Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Top Kudoed Authors
Users online (3,187)