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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
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,286
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,446
Messages
5,642,198
Members
417,259
Latest member
gtacw

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