am still learning vba - how hard would it be to create a macro that would order all the tabs by what i specify on the front page?

bigdan

Well-known Member
Joined
Oct 5, 2009
Messages
843
Office Version
  1. 2013
Platform
  1. Windows
i'm still learning VBA so dont know this. but id like to know if being able to create this program is in the cards in the next little while or is this going to be much later?

essentially i'll have a hundred or so tabs. on the front page i'd like to specify the order they should be in. and i'd like the macro to put them in that order. if there's tabs that aren't mentioned in the front page then they can do in ascending order at the end.

how difficult woudl this be?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
VBA Code:
Sub TabsSort()
Dim i&, j&
For i = 2 To Sheets.Count
    For j = 2 To Sheets.Count - 1
        If UCase(Sheets(j).Name) > UCase(Sheets(j + 1).Name) Then _
           Sheets(j).Move after:=Sheets(j + 1)
    Next
Next
On Error Resume Next
With Sheets("SheetList")
    For i = .Range("A" & Rows.Count).End(3).Row To 1 Step -1
        Sheets(.Cells(i, 1).Value).Move Before:=Sheets(2)
    Next
End With
On Error GoTo 0
End Sub
There's plenty of this sort of code available on the internet.
 
Upvote 0
Thanks! I'm afraid that didn't work though. I suppose I need to have knowledge of VBA in order to fine tune it. I put the order in the first tab, in A2 onwards, with A1 as the header. Should I have put it somewhere else?
 
Upvote 0
In what way did it not work? Any error message?
Is your sheet containing the list the same as the sheet name in the macro?
 
Upvote 0
I put the order in the first tab, in A2 onwards, with A1 as the header.
See if this does what you want.
Test with a copy of your workbook.

VBA Code:
Sub ArrangeSheets()
  Dim AL As Object
  Dim itm As Variant
  Dim i As Long, NumSh As Long
  Dim shName As String
  
  Set AL = CreateObject("System.Collections.ArrayList")
  NumSh = Sheets.Count
  For i = 2 To NumSh
    AL.Add Sheets(i).Name
  Next i
  AL.Sort
  Application.ScreenUpdating = False
  With Sheets(1)
    For i = 2 To .Range("A" & Rows.Count).End(xlUp).Row
      shName = .Cells(i, "A").Value
      Sheets(shName).Move After:=Sheets(NumSh)
      AL.Remove shName
    Next i
  End With
  For Each itm In AL.ToArray
    Sheets(itm).Move After:=Sheets(NumSh)
  Next itm
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,575
Members
449,089
Latest member
Motoracer88

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