web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to get dynamically...
Power Automate
Answered

How to get dynamically the last excel worksheet, copy the data and paste in a new worksheet?

(0) ShareShare
ReportReport
Posted on by 1,712

Hello everyone,

I started learning Power Automate Desktop and I am trying to achieve the below scenario:

1. Launch an excel file.
2. Get the last tab or go to the last tab and copy all information from the previous tab.
3. Create a new tab and paste the information in.

So basically an excel sheet might have 20 worksheets and during the flow process, it should always find the last excel worksheet -> copy the data from the previous worksheet (worksheet no.19) -> create a new worksheet and paste the information that is coming from the worksheet no.19.

It is not always 20 worksheets so the flow should be dynamic and always find the last sheet.

What I tried is the below:
PDA screenshot.png
COpy to sheet 5.png

However, I am still struggling to get the last worksheet and the one before the last worksheet - 1 to copy the data and paste in a new worksheet.

Could please provide some screenshots or an example on how to achieve the above?
Any help is highly appreciated.

Best regards,
Julien

  • Verified answer
    VJR Profile Picture
    7,635 on at

    Hi @Julien2 

     

    Lets assume "Get all Excel Worksheets" returns the below Datatable.

    VJR_1-1647834476599.png

     

     

    Then no need to use a loop. Directly use the count of the datatable with minus 1 and minus 2 from the count.

    The Datatable starts from 0, but the count starts from 1. Therefore need to use as below.

     

    The last sheet name is: %SheetNames[SheetNames.Count - 1]%
    
    The second last sheet name is: %SheetNames[SheetNames.Count - 2]%
    

     

     

    VJR_0-1647834421588.png

     

  • EBMRay Profile Picture
    1,712 on at

    Hello @VJR ,

    Thank you for providing the above example and screenshots.

    As the next step since now we have the "second last sheet name", how can I copy this data from this sheet and paste it into a new worksheet?

    I found the action to create a new worksheet but I am struggling with the action that should be used to read only the second last sheet name.

    Could you please also provide an example of that scenario?

    Awaiting your response.
    Best regards,
    Julien

  • VJR Profile Picture
    7,635 on at

    @Julien2 

    you can first activate the worksheet you want using "Set active Excel worksheet" then copy the cells and then again activate the other worksheet and then paste. Hope this helps.

  • EBMRay Profile Picture
    1,712 on at

    Hello @VJR ,

    Thank you so much for your reply. It worked perfectly.

    Have a nice week ahead!

    Best regards,
    Julien

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 275 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 235

#3
David_MA Profile Picture

David_MA 178 Super User 2026 Season 2

Last 30 days Overall leaderboard