Skip to main content
Community site session details

Community site session details

Session Id : F9UCuqn1nBaRA+0nNKmOt/
Power Automate - Power Automate Desktop
Answered

Help for loop thru worksheets in a Excel File

Like (0) ShareShare
ReportReport
Posted on 2 May 2024 16:31:13 by 17

Hello All,   

 

I have only done a few desktop flows and stuck on this one I am working on now.

I receive an Excel report with multiple worksheets (tabs) each month. I separate them to condense them into their own Excel Workbook using the worksheet name. I will copy and paste the next month (& so on) into the new file.

 

I have successfully created the flow for the first tab, but stuck on creating an "If /loop" to go thru each tab.   

 

I need the IF statement - as each original file will have different # of worksheets included each month. I attached the flow to date.

 

End Goal (Making a file for each one of these).

1Suz_1-1714667227006.png

 

 

Power Automate Desktop multiple worksheets loop thru flow.png

 

Thank you so much.

Susan Boyles

  • Verified answer
    1Suz Profile Picture
    17 on 03 May 2024 at 15:13:55
    Re: Help for loop thru worksheets in a Excel File

    @Deenuji 

    Wonderful & thank you again.  

    Have a wonderful day.

     

    Best Regards,

    Suzzi

  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,204 Super User 2025 Season 2 on 03 May 2024 at 15:09:59
    Re: Help for loop thru worksheets in a Excel File

    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

    And regarding your couple of questions,


    1) Is there a reason (is C/Boot that you had in your code (which failed when I tried after the one drive didn't work)? You can change into your local folder. I want to save my worksheet in that folder, so I have configured that path.

     

    2) For next month, should I create a new flow (copying this one as I will still need to separate the date, but   instead of saving to a new file the worksheet will be extracted and adding to the file created by the above flow.  Yes you can use this flow as base one and you can modify it as per your business logics. Next month you can try, in case facing any issues you can raise one more new topic like this.

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥


  • 1Suz Profile Picture
    17 on 03 May 2024 at 14:19:50
    Re: Help for loop thru worksheets in a Excel File

    Hello @Deenuji ,


    Thank you for your assistance. 

    The flow is successful sans saving to the One Drive Folder

    The flow is success with saving to the desktop folder.

     

    1) Is there a reason (is C/Boot that you had in your code (which failed when I tried after the one drive didn't work)?

     

    2) For next month, should I create a new flow (copying this one as I will still need to separate the date, but   instead of saving to a new file the worksheet will be extracted and adding to the file created by the above flow. 

     

    I would keep the same loop process, correct?  By the end of the year, I should have 6 files with 12 worksheets each.  

     

    Thank you again and I appreciate the time.

    Best regards,

    Suzzi

  • 1Suz Profile Picture
    17 on 02 May 2024 at 18:50:59
    Re: Help for loop thru worksheets in a Excel File

    @Deenuji 

    Thank you, I will do that.  I appreciate the feedback.  

     

    Best regards,

    Suzzi 

  • Deenuji_Loganathan_ Profile Picture
    6,204 Super User 2025 Season 2 on 02 May 2024 at 17:26:48
    Re: Help for loop thru worksheets in a Excel File

    @1Suz 

     

    You've created your desktop flow using the Power FX feature, which is currently in its preview stage. However, I wouldn't suggest using it for live projects just yet. So recreate your desktop flow just disabled power fx as mentioned in the below screenshot and follow the below instructions.

     

    Deenuji_4-1714671071869.png

     

     

    Please follow the below approach:

    Deenuji_0-1714670695868.png

     

    My Input excel file:

    Deenuji_1-1714670797175.png

     

    Output:

    Deenuji_2-1714670855919.png

     

     

    Code:

     

    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\deenu\\OneDrive\\Documents\\Split.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.GetAllWorksheets Instance: ExcelInstance Worksheets=> SheetNames
    LOOP FOREACH CurrentSheet IN SheetNames
     Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: CurrentSheet
     Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: True RangeValue=> ExcelData
     Excel.LaunchExcel.LaunchUnderExistingProcess Visible: True Instance=> ExcelInstance1
     Excel.WriteToExcel.WriteNamedCell Instance: ExcelInstance1 Value: ExcelData.ColumnHeadersRow CellName: $'''A1'''
     Excel.WriteToExcel.WriteCell Instance: ExcelInstance1 Value: ExcelData Column: $'''A''' Row: 2
     Excel.SaveExcel.SaveAs Instance: ExcelInstance1 DocumentFormat: Excel.ExcelFormat.FromExtension DocumentPath: $'''C:\\Boot\\%CurrentSheet%.xlsx'''
    END

     

     

    How to copy/paste the above code into you PAD?

    Deenuji_3-1714670925794.gif

     

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Loading complete