Select all sheets in workbook

aaronward

Board Regular
Joined
Aug 2, 2006
Messages
165
here is the code i have:

Code:
Sheets(Array("Master", "4001", "4002", "4003", "4004", "4005")).Select

but i dont know how many sheet i will always have or their names, is there any way i have select all sheets in stead of each individual one?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Why do you need to select them?
 
Upvote 0
here is the rest of the code, i am wanting to autofit all sheets, then activate my main sheet:

Code:
Sheets(Array("Master", "4001", "4002", "4003", "4004", "4005")).Select
    Cells.Select
    Cells.EntireColumn.AutoFit
    Sheets(1).Select

but i wont always know how many sheets i have, i may i have 4 or i may have 10...thanks!
 
Upvote 0
Well for a start there's no need to select.

Try this.
Code:
Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Cells.EntireColumn.AutoFit
    Next ws
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top