LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Looping or Repeating on all worksheets

I want to repeat this on all worksheets, without individually selecting each
sheet and running the macro. I want the macro to run on all sheets and stop
at the end. I am using this on a weekly back order report, so the worksheet
names change weekly, but the name of each column is the same from A:L.
Please help, I can't seem to find info about this.
Here is what I have found so far, it works for each sheet individually, but
I want it to do all sheets at once.

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 Worksheet

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 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
For Each sh In ThisWorkbook.Worksheets

Columns("A:L").Select
Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Key2:=Range("B2") _
, Order2:=xlAscending, Key3:=Range("H2"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortTextAsNumbers,
DataOption3 _
:=xlSortNormal
Next
End Sub

 
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
How do I display repeating text between worksheets only once on ta Paul New Users to Excel 1 August 11th 09 01:23 PM
How do i use the same name multiple times in repeating worksheets Chris.Daniels Excel Discussion (Misc queries) 1 October 11th 06 10:47 AM
Repeating some code on all worksheets matpj[_29_] Excel Programming 6 January 12th 06 12:26 PM
Repeating macro procedure on several worksheets Shandy720[_6_] Excel Programming 3 October 11th 05 03:06 PM
Repeating (Looping) a Macro David Patterson Excel Programming 10 August 5th 03 04:27 AM


All times are GMT +1. The time now is 07:08 AM.

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"