Re: Sort all worksheet contents with a macro
- From: Ren <Ren@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 28 Jan 2008 19:32:33 -0800
Hi Tom,
i have multiple sheets from A to Z
and i need to sort column L
i used this code
Sub sort()
cells.sort Key1:=range("L2"), Header:=xlYes
End Sub
it's working for the single ***.
but i want it for all sheets.
how to modify your code.i tried but could't get thru.
thanks in advance
Ren
"Tom Ogilvy" wrote:
Sub SortWorksheets().
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
Dim sh as Work***
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 UCase(Worksheets(N).Name) > _
UCase(Worksheets(M).Name) Then
Worksheets(N).Move Before:=Worksheets(M)
End If
Else
If UCase(Worksheets(N).Name) < _
UCase(Worksheets(M).Name) Then
Worksheets(N).Move Before:=Worksheets(M)
End If
End If
Next N
Next M
for each sh in Thisworkbook.Worksheets
sh.UsedRange.Sort Key1:=sh.Range("A1"), _
Order1:=xlAscending, Header:=xlYes
Next
End Sub
Adjust the header setting to fit your data.
--
Regards,
Tom Ogilvy
"Scott" <Scott@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FB9C4095-FCF0-4CEB-8DF9-BD2709D238D3@xxxxxxxxxxxxxxxx
I have searched the boards and have not found what I need. Hoping you canand
help. I am using the following to sort work*** order within a workbook
it is working perfectly.contents
http://www.cpearson.com/excel/sortws.htm
What I still haven't found is how to re-sort (by first column) the
of all worksheets. Idea situation would be to combine this with the item
referenced above.
Thanks in advance.
Scott
- Prev by Date: Re: creating a macro to add text to existing data already in cell
- Next by Date: Re: 2003 vs 2007
- Previous by thread: convert hyperlink to email address
- Next by thread: Re: Userform TabStrip questions
- Index(es):