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


Hi:

Dave Peterson helped me put together the following macro that sorts al
the worksheets in my workbook *starting with* the 20th sheet. Because
keep adding sheets to the workbook, I'm constantly having to change th
"FirstWStoSort" value (see below) to make sure that certain sheets don'
get sorted. I have decided to insert a "dummy" worksheet calle
"aaaDoNotDelete" before the first sheet that I want included in th
sort. What do I have to do to change the macro so that instead of th
sorting beginning after a specfied *number * of worksheets, it no
starts after a *specific * worksheet - namely "aaaDoNotDelete". I'
assuming that's a "no brainer" task but I'm a relative newbie to macro
in general.

Thanks in advance for your help.

Dave

Sub zzSortWorksheetsAlphabetically()

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 = 19* 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 UCase(Worksheets(N).Name) UCase(Worksheets(M).Name
Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name
Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Su

--
sns
-----------------------------------------------------------------------
snsd's Profile: http://www.excelforum.com/member.php...fo&userid=1591
View this thread: http://www.excelforum.com/showthread.php?threadid=32020

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort Certain Worksheets in Workbook

Sub zzSortWorksheetsAlphabetically()

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 = 19*
FirstWSToSort = Sheets("aaaDoNotDelete").Index + 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 UCase(Worksheets(N).Name) UCase(Worksheets(M).Name)
Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name)
Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Sub

--
Regards,
Tom Ogilvy


"snsd" wrote in message
...

Hi:

Dave Peterson helped me put together the following macro that sorts all
the worksheets in my workbook *starting with* the 20th sheet. Because I
keep adding sheets to the workbook, I'm constantly having to change the
"FirstWStoSort" value (see below) to make sure that certain sheets don't
get sorted. I have decided to insert a "dummy" worksheet called
"aaaDoNotDelete" before the first sheet that I want included in the
sort. What do I have to do to change the macro so that instead of the
sorting beginning after a specfied *number * of worksheets, it now
starts after a *specific * worksheet - namely "aaaDoNotDelete". I'm
assuming that's a "no brainer" task but I'm a relative newbie to macros
in general.

Thanks in advance for your help.

Dave

Sub zzSortWorksheetsAlphabetically()

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 = 19* 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 UCase(Worksheets(N).Name) UCase(Worksheets(M).Name)
Then
Worksheets(N).Move Befo=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < UCase(Worksheets(M).Name)
Then
Worksheets(N).Move Befo=Worksheets(M)
End If
End If
Next N
Next M
End Sub


--
snsd
------------------------------------------------------------------------
snsd's Profile:

http://www.excelforum.com/member.php...o&userid=15910
View this thread: http://www.excelforum.com/showthread...hreadid=320205



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
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
Sort all worksheets in a workbook jlclyde Excel Discussion (Misc queries) 3 November 26th 08 05:00 PM
Is there a way to sort worksheets within a workbook Mim Excel Discussion (Misc queries) 6 October 23rd 07 03:48 PM
How do I sort data from various worksheets in the same workbook i. Evelyne Excel Worksheet Functions 4 April 1st 05 06:57 PM
I want to sort worksheets in a workbook into Alpha order? thecattah Excel Worksheet Functions 1 January 5th 05 07:06 AM


All times are GMT +1. The time now is 09:00 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"