Copy last sheet everytime in Excel

How do i copy/duplicate the last sheet everytime i run the project.

Example: I got sheet 1 and sheet 2 in a Excel file

i run the project, and it gives me sheet 1, sheet 2, and sheet 3


When i try to run again.

I want to let the program copy the sheet from sheet 3(the lastest sheet)

Thus having sheet 1, sheet 2, sheet 3, and sheet 4(the newly created sheet)


Welcome to the community

Use get worksheets activity …to get attay of all worksheets

If the sheetname is always in this format then use

Arrvar.OrderBy(function(x) Cint(System.Text.RegularExpressions.Regex.Match(x,"\d+").Value))(0)

This will give the latest sheetname…Arrvar is output of get sheets


Cheers i try doing it

1 Like

Hi Anil_G

Seems my StudioX doesn’t have the Get worksheets activity. is there a work around on this?


Create a integer variable max and give initialvalue as 0 and create a sheetnm varaible of type string

Use for each excel sheet activity…inside that you will get each sheetname…use if condition inside as below

cint(System.Text.RegularExpressions.Regex.Match(x,"\d+").Value) > max

On the then side use assign with sheetnm = currentsheet.Name

and one more assign as Max = cint(System.Text.RegularExpressions.Regex.Match(x,"\d+").Value)

After the loop you would get the highest sheet name in sheetnm

Hope this helps


Thanks Anil_G but the expression doesn’t still work. But still thanks for the assistant.


Instead of expression use matches activity …even that would work in the same way…the output of it can be used in the if condition




Thanks for the diligent help, but for a beginner developers like myself, i don’t understand most of the used of every activities and the solution your giving me. But Thanks really. i might just let this problem pass by.

1 Like


  1. I am looping through each sheet…which is for each excel sheet
  2. Using matches activity which \d+ will extract the number from the given string
  3. Now I am using If to compare the max number number and store it if it is maximum and then storing the corresponding sheet to a variable and then also change max to the new max value

Would suggest go through and do some basic training first


To achieve this, you can use the Copy Sheet activity in UiPath. Here is an example workflow that you can use:

  1. Use the Excel Application Scope activity to open the Excel file.
  2. Use the Read Range activity to read the data from the last sheet in the workbook.
  3. Use the Copy Sheet activity to copy the last sheet to a new sheet with a unique name.
  4. Use the Write Range activity to write the data to the new sheet.
  5. Close the Excel Application Scope activity.