Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default sorting the tabs

Hi

Say, a workbook has 12 worksheets, and their tabs are color coded - 3
different colors for 3 groups of tab. The order of color on each tab is
random. The objective is to move the tabs so that the colors are grouped
together - no matter which one is first.

For example:
Random colored tabs:
red,green,blue,red,green,blue,red,green,blue,red,g reen,blue
Sorted colored tabs:
red,red,red,red,green,green,green,green,blue,blue, blue,blue

Note: Green or blue can be first ... it doesn't matter.

Please help with some sample code or pseudo code.

Thank you
Steve


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default sorting the tabs

SP,

This is modified from Chip Pearson's code he

http://www.cpearson.com/excel/sortws.htm

Sub SortWorksheets()

Dim N As Long
Dim M As Long
Dim SortDescending As Boolean

SortDescending = False

With ActiveWorkbook.Sheets
For M = 1 To .Count
For N = M To .Count
If SortDescending = True Then
If Worksheets(N).Tab.ColorIndex
Worksheets(M).Tab.ColorIndex Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If Worksheets(N).Tab.ColorIndex <
Worksheets(M).Tab.ColorIndex Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End With

End Sub

hth,

Doug

"SP" wrote in message
...
Hi

Say, a workbook has 12 worksheets, and their tabs are color coded - 3
different colors for 3 groups of tab. The order of color on each tab is
random. The objective is to move the tabs so that the colors are grouped
together - no matter which one is first.

For example:
Random colored tabs:
red,green,blue,red,green,blue,red,green,blue,red,g reen,blue
Sorted colored tabs:
red,red,red,red,green,green,green,green,blue,blue, blue,blue

Note: Green or blue can be first ... it doesn't matter.

Please help with some sample code or pseudo code.

Thank you
Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default sorting the tabs

Thank you very much for the fast response. The code really helps.

Steve

"Doug Glancy" wrote in message
...
SP,

This is modified from Chip Pearson's code he

http://www.cpearson.com/excel/sortws.htm

Sub SortWorksheets()

Dim N As Long
Dim M As Long
Dim SortDescending As Boolean

SortDescending = False

With ActiveWorkbook.Sheets
For M = 1 To .Count
For N = M To .Count
If SortDescending = True Then
If Worksheets(N).Tab.ColorIndex
Worksheets(M).Tab.ColorIndex Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If Worksheets(N).Tab.ColorIndex <
Worksheets(M).Tab.ColorIndex Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End With

End Sub

hth,

Doug

"SP" wrote in message
...
Hi

Say, a workbook has 12 worksheets, and their tabs are color coded - 3
different colors for 3 groups of tab. The order of color on each tab is
random. The objective is to move the tabs so that the colors are grouped
together - no matter which one is first.

For example:
Random colored tabs:
red,green,blue,red,green,blue,red,green,blue,red,g reen,blue
Sorted colored tabs:
red,red,red,red,green,green,green,green,blue,blue, blue,blue

Note: Green or blue can be first ... it doesn't matter.

Please help with some sample code or pseudo code.

Thank you
Steve





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting Spreadsheet to Different Tabs Meredith Excel Discussion (Misc queries) 2 December 31st 08 04:14 PM
Sorting Worksheet Tabs Jaqi Excel Worksheet Functions 5 July 15th 08 08:54 PM
Sorting Worksheet Tabs The Rook[_2_] Excel Discussion (Misc queries) 1 October 24th 07 11:12 AM
Sorting Tabs Greg B Excel Discussion (Misc queries) 2 April 26th 05 03:20 PM
sorting tabs Suz Excel Discussion (Misc queries) 1 January 11th 05 06:28 PM


All times are GMT +1. The time now is 03:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"