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
Done.
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)
Anil_G
(Anil Gorthi)
April 7, 2023, 9:12am
2
@Joshua_Ducao
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
Hi Anil_G
Seems my StudioX doesn’t have the Get worksheets activity. is there a work around on this?
Anil_G
(Anil Gorthi)
April 7, 2023, 9:33am
5
@Joshua_Ducao
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
Cheers
Thanks Anil_G but the expression doesn’t still work. But still thanks for the assistant.
Anil_G
(Anil Gorthi)
April 7, 2023, 10:08am
7
@Joshua_Ducao
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
Cint(outputofit(0).value)>max
Cheers
@Anil_G
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
Anil_G
(Anil Gorthi)
April 7, 2023, 10:41am
9
@Joshua_Ducao
I am looping through each sheet…which is for each excel sheet
Using matches activity which \d+ will extract the number from the given string
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 academy.uipath.com and do some basic training first
cheers
Nitya1
(Nitya Tomar)
April 7, 2023, 4:21pm
10
To achieve this, you can use the Copy Sheet activity in UiPath. Here is an example workflow that you can use:
Use the Excel Application Scope activity to open the Excel file.
Use the Read Range activity to read the data from the last sheet in the workbook.
Use the Copy Sheet activity to copy the last sheet to a new sheet with a unique name.
Use the Write Range activity to write the data to the new sheet.
Close the Excel Application Scope activity.