Macro to select all sheets

  • Thread starter Thread starter Dave Rey
  • Start date Start date
D

Dave Rey

I have a workbook containing many worksheets.

I am trying to write a macro which will select all
sheets. When I record a macro, the code looks like this:

"ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets(Array
("Sheet1", "sheet2", "sheet3","sheetn")).Select"

Where each sheet has a different name (not shown above)
and sheetn is the name of the last sheet.

Is there any way of achieveing the same as above, but with
the array being from "first sheet in book" to "last sheet
in book" - thereby enabling me to add sheets, rename them
etc and the macro automatically include the new ones?

Thanks

Dave
 
Hi Dave

If you only want to select them use

Sheets.Select
Or
Worksheets.Select

Or do you want to do something on each sheet ?

Sub test()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
MsgBox sh.Name
Next sh
End Sub
 
Nope - selecting them is fine - I can write the rest of
the code around that.

Thanks!

Dave
-----Original Message-----
Hi Dave

If you only want to select them use

Sheets.Select
Or
Worksheets.Select

Or do you want to do something on each sheet ?

Sub test()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
MsgBox sh.Name
Next sh
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Dave Rey" <[email protected]> wrote in
message news:[email protected]...
 
Back
Top