Reorder sheets and color tabs based on list

willastrowalker

New Member
Joined
Aug 28, 2015
Messages
9
I have a workbook that I want to reorder and recolor based on a list of sheetnames and color indexes on a tab.. I have working code for reordering, but want to add in code to recolor the tabs.

List of Sheet for ordering is in column A, color codes are in column B (total number of sheets changes, so need the color index to change with the list)

Code:
Sub Sort_Sheets()  Dim i As Long
  Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Application.Calculation = xlCalculationManual
  
  With Sheets("SheetOrder")
    On Error Resume Next
    For i = .Range("A" & .Rows.Count).End(xlUp).Row To 1 Step -1
      Sheets(.Cells(i, 1).Value).Move Before:=Sheets(1)
    Next i
    On Error GoTo 0
  End With
    Application.ScreenUpdating = True
    Application.DisplayStatusBar = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationAutomatic


End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this:

Remember now we only have 56 colorindex colors so never enter any value in column 2 greater then 56
Code:
Sub Sort_Sheets()
'Modified  9/14/2018  5:26:03 PM  EDT
Dim i As Long
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
  
  With Sheets("SheetOrder")
    On Error Resume Next
    For i = .Range("A" & .Rows.Count).End(xlUp).Row To 1 Step -1
        Sheets(.Cells(i, 1).Value).Move Before:=Sheets(1)
        Sheets(.Cells(i, 1).Value).Tab.ColorIndex = .Cells(i, 2).Value
      
    Next i
    On Error GoTo 0
  End With
    Application.ScreenUpdating = True
    Application.DisplayStatusBar = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationAutomatic

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,962
Members
449,200
Latest member
indiansth

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