• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to Group Worksheets by Color

Hello Experts!

we work with huge workbooks and keep on adding them as per the requirment with some color code, can we group them by color by any chance..we are doing it manually by dragging sheets.

Thanking you in advance!
 
Try this..Not
Code:
Sub Group_Testing()

'Step 1: Declare your Variables
    Dim CurrentSheetIndex As Integer
    Dim PrevSheetIndex As Integer

'Step 2: Set the starting counts and start looping
    For CurrentSheetIndex = 1 To Sheets.Count
    For PrevSheetIndex = 1 To CurrentSheetIndex - 1

'Step 3: Check Current Sheet against Previous Sheet
    If Sheets(PrevSheetIndex).Tab.ColorIndex = _
    Sheets(CurrentSheetIndex).Tab.ColorIndex Then

'Step 4: If Move Current sheet Before Previous
    Sheets(PrevSheetIndex).Move _
    Before:=Sheets(CurrentSheetIndex)
    End If

'Step 5 Loop back around to iterate again
    Next PrevSheetIndex
    Next CurrentSheetIndex

End Sub
Tested
 
Hey champ.

It works tested with working with four sheets with colors.
need to check with the actual file on monday as logged off from sys.
Thank you so very much for your help.
 
Hi Monty,

I tried. but sometimes need to run twice to achieve the result.

I have modified abit on the code as highlighted although it takes slightly longer time.


Sub Group_Testing()

'Step 1: Declare your Variables
Dim CurrentSheetIndex AsInteger
Dim PrevSheetIndex AsInteger

'Step 2: Set the starting counts and start looping
For CurrentSheetIndex = 1 To Sheets.Count -1
For PrevSheetIndex = 2 To Sheets.Count


'Step 3: Check Current Sheet against Previous Sheet If Sheets(PrevSheetIndex).Tab.ColorIndex = _
Sheets(CurrentSheetIndex).Tab.ColorIndex Then

'Step 4: If Move Current sheet Before Previous
Sheets(PrevSheetIndex).Move _
Before:=Sheets(CurrentSheetIndex)
EndIf

'Step 5 Loop back around to iterate again Next PrevSheetIndex
Next CurrentSheetIndex

EndSub
 
Back
Top