Automatically arrange tabs in alphabetical order

tlc53

Active Member
Joined
Jul 26, 2018
Messages
380
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
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,570
Office Version
  1. 365
Platform
  1. Windows
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
 
Solution

tlc53

Active Member
Joined
Jul 26, 2018
Messages
380
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 :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,570
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,613
Messages
5,625,848
Members
416,139
Latest member
MattBoard

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
Top