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.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
Why do you need to select them?
 

aaronward

Board Regular
Joined
Aug 2, 2006
Messages
165
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!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,351
Office Version
  1. 365
Platform
  1. Windows
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,701
Messages
5,855,239
Members
431,716
Latest member
Ibyb

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
Top