ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting all of the sheets in a workbook (https://www.excelbanter.com/excel-programming/398909-selecting-all-sheets-workbook.html)

Cyberwolf

Selecting all of the sheets in a workbook
 
How would I go creating a macro or VBA that selects all of the worksheets in
a given workbook. This needs to work regardless of how many sheets there
are. i.e. workbook1 may contain 5 worksheets where as workbook2 may
contain 8.
--
Cyberwolf
Finder of Paths, Hunter of Prey
Ghost of the Night, Shadow of Day
The Wolf

JW[_2_]

Selecting all of the sheets in a workbook
 
This will select all visible sheets.
Sub selectAll()
Dim ws As Worksheet
For Each ws In Sheets
If ws.Visible Then ws.Select False
Next
End Sub
Cyberwolf wrote:
How would I go creating a macro or VBA that selects all of the worksheets in
a given workbook. This needs to work regardless of how many sheets there
are. i.e. workbook1 may contain 5 worksheets where as workbook2 may
contain 8.
--
Cyberwolf
Finder of Paths, Hunter of Prey
Ghost of the Night, Shadow of Day
The Wolf



Don Guillett

Selecting all of the sheets in a workbook
 
sheets.select

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Cyberwolf" wrote in message
...
How would I go creating a macro or VBA that selects all of the worksheets
in
a given workbook. This needs to work regardless of how many sheets there
are. i.e. workbook1 may contain 5 worksheets where as workbook2
may
contain 8.
--
Cyberwolf
Finder of Paths, Hunter of Prey
Ghost of the Night, Shadow of Day
The Wolf



JW[_2_]

Selecting all of the sheets in a workbook
 
Don, that could will work perfectly as long as no sheets are hidden.
If there are hidden sheets in the workbook, a 1004 error occurs.

Regards,
Jeff
Don Guillett wrote:
sheets.select

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Cyberwolf" wrote in message
...
How would I go creating a macro or VBA that selects all of the worksheets
in
a given workbook. This needs to work regardless of how many sheets there
are. i.e. workbook1 may contain 5 worksheets where as workbook2
may
contain 8.
--
Cyberwolf
Finder of Paths, Hunter of Prey
Ghost of the Night, Shadow of Day
The Wolf




All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com