View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Run Macro on All Sheets Q

Just another way to do the same thing without hard-coding the
sheetnames inside the routine...

Sub LoopSheets(ExcludedSheets$)
Dim wks As Worksheet
For each wks In ActiveWorkbook.Worksheets
If Not InStr(1, ExcludedSheets, wks.Name) 0 Then _
wks.Activate: Call MainMacro
Next 'wks
End Sub

...where the sheets to be excluded from the process are a delimited
string that can be assigned 'on-the-fly'!

-OR-

Sub MainMacro(Wks As Worksheet)
With Wks
'//do stuff
End With 'Wks
End Sub

...then revise LoopSheets as follows...

Sub LoopSheets(ExcludedSheets$)
Dim wks As Worksheet
For each wks In ActiveWorkbook.Worksheets
If Not InStr(1, ExcludedSheets, wks.Name) 0 Then _
Call MainMacro(wks)
Next 'wks
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion