Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to sort Worksheets

I have a file with a potentially variable number of worksheets. However
all worksheets will be exactly the same except for the Summary sheet
need to sort the sheets in an order based on the cell value in cel
c105. So, I have a Summary sheet where I want the sheet names to b
listed. Alongside, I then want the value recorded of cell c105. I woul
then data sort the range based on the values. Then i rename the sheets
Sheet2,Sheet3 etc by means of variables to sort them into the order an
then reassign the original sheet names.
Does anyone have any clever code to deal with this?
Thank

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to sort Worksheets

You can skip all that by modify Chip Pearson's code to look at cell C105

http://www.cpearson.com/excel/sortws.htm
Sub SortWorksheets()

Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean

SortDescending = False

If ActiveWindow.SelectedSheets.Count = 1 Then
FirstWSToSort = 1
LastWSToSort = Worksheets.Count
Else
With ActiveWindow.SelectedSheets
For N = 2 To .Count
If .Item(N - 1).Index < .Item(N).Index - 1 Then
MsgBox "You cannot sort non-adjacent sheets"
Exit Sub
End If
Next N
FirstWSToSort = .Item(1).Index
LastWSToSort = .Item(.Count).Index
End With
End If

For M = FirstWSToSort To LastWSToSort
For N = M To LastWSToSort
If SortDescending = True Then
If Worksheets(N).Range("C105") _
Worksheets(M).Range("C105) Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If Worksheets(N).Range("C105") < _
Worksheets(M).Range("C105) Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Sub

--
Regards,
Tom Ogilvy




"Stuart Farr " wrote in message
...
I have a file with a potentially variable number of worksheets. However,
all worksheets will be exactly the same except for the Summary sheetI
need to sort the sheets in an order based on the cell value in cell
c105. So, I have a Summary sheet where I want the sheet names to be
listed. Alongside, I then want the value recorded of cell c105. I would
then data sort the range based on the values. Then i rename the sheets,
Sheet2,Sheet3 etc by means of variables to sort them into the order and
then reassign the original sheet names.
Does anyone have any clever code to deal with this?
Thanks


---
Message posted from http://www.ExcelForum.com/



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
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Help:macro to auto sort data to different worksheets... 2nd Time Around Excel Discussion (Misc queries) 2 August 6th 05 12:31 PM
How do I sort Worksheets by name? M Skabialka New Users to Excel 4 April 7th 05 06:15 PM
Sort Numerically Worksheets via VB when creating a new worksheets John Excel Programming 6 June 1st 04 07:21 AM
HELP sort 2 worksheets Malycom Excel Programming 2 February 16th 04 09:55 AM


All times are GMT +1. The time now is 01:53 AM.

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

About Us

"It's about Microsoft Excel"