How rearrange sheets in uipath?

Hello everyone!
I have 4 sheets in my excel workbook like : [‘Data’, ‘Orders’, ‘Expiry’, ‘Customer’] I want to arrange them like [‘Customer’, ‘Orders’, ‘Data’, ‘Expiry’]

How can i do this ?

Please refer to the below thread,

Hi @prabin_chand1

Can you try with this script

Sub SheetsAscending ()
For i = 1 To Application.Sheets.Count
For j = 1 To Application.Sheets.Count - 1
If UCase$ (Application.Sheets (j).Name) > UCase$ (Application.Sheets (j + 1).Name) Then
Sheets (j).Move after:=Sheets (j + 1)
End If
Next
Next
End Sub

If you want to rearrange sheets in a specific order, you can modify the above code by replacing the sorting condition with your desired order

Regards
Gokul

1 Like

How to reference my excel workbook with this code ?

Hi @prabin_chand1

To reference your Excel workbook with the code I provided earlier, you can use the following code:

Sub SheetsAscending ()
Dim wb As Workbook
Set wb = Workbooks.Open("C:\Users\user\Documents\Book1.xlsx")
For i = 1 To wb.Sheets.Count
For j = 1 To wb.Sheets.Count - 1
If UCase$ (wb.Sheets (j).Name) > UCase$ (wb.Sheets (j + 1).Name) Then
wb.Sheets (j).Move after:=wb.Sheets (j + 1)
End If
Next
Next
End Sub

You can replace “C:\Users\user\Documents\Book1.xlsx” with the path to your Excel workbook.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.