Automatically arrange tabs in alphabetical order

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hello,
I'm wondering, is it possible for a VBA code to automatically sort the tabs by alphabetical order?
It is quite a large spreadsheet, with 42 tabs.
The first 3 tabs shouldn't be included when they are sorted. These tabs are called;
- Dashboard
- Invoice Data
- Client Details
The tabs following these are client invoice tabs and they are named/coded by 3x Letters and 2x numbers. For example;
AAP01
GRM01
GRM02
HER01
HER02
HER03
MER01
MER02
These tab names (above) can be changed depending on what clients are active. Unused/blank tabs are named ZZZ01, ZZZ02, ZZZ03 etc and they are kept at the end of the spreadsheet. These can be used to setup new clients. For example, ZZZ01 may turn into a client code BEB01.
As the spreadsheet it quite large, sorting the tabs manually takes quite a bit of time, especially when the tab needs to move from one end to the other.
Ideally, I would like the user to be able to activate a VBA code after amending/adding clients, so that it will automatically sort all the client tabs.
Thanks for your time!
Cheers
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How about
VBA Code:
Sub tlc()
   Dim i As Long
   With CreateObject("system.collections.arraylist")
      For i = 4 To Sheets.Count
         .Add Sheets(i).name
      Next i
      .Sort
      For i = 0 To .Count - 1
         Sheets(.item(i)).Move Sheets(i + 4)
      Next i
   End With
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub tlc()
   Dim i As Long
   With CreateObject("system.collections.arraylist")
      For i = 4 To Sheets.Count
         .Add Sheets(i).name
      Next i
      .Sort
      For i = 0 To .Count - 1
         Sheets(.item(i)).Move Sheets(i + 4)
      Next i
   End With
End Sub
Lovely jubbly. Thank you! That worked perfectly :)
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,749
Members
449,050
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top