Select all sheets in VBA

oliver_penney

Board Regular
Joined
Dec 18, 2002
Messages
182
there is probably a one line answer to this, but how do i select all (visible) sheets?

if a record a macro it creates an array of the worksheet names, which is no good if the names change

thanx in advance

ol
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the Board!<pre>
Sheets.Select</pre>

that should do it.

EDIT:: Should've tested that with some hidden sheets really shouldn't I? Nate Oliver's solution is the way to go.
_________________<font color = green> Mark O'Brien </font>

Columbus Ohio Celtic Supporters Club
This message was edited by Mark O'Brien on 2002-12-19 10:48
 
Upvote 0
Howdy Oliver (sharp name!), welcome to the board. How's about the following:

<pre>
Sub gram_em()
Dim ws As Worksheet
For Each ws In Sheets
If ws.Visible Then ws.Select (False)
Next
End Sub</pre>
 
Upvote 0
Hi Nate,

What the use for "(false)" in that syntax?
If i using that syntax, error message appear

"run time error '1004'
application-defined or object-defined error"

But when i delete the (false), all the syntax work like charm
 
Upvote 0
Hi Nate,

What the use for "(false)" in that syntax?
If i using that syntax, error message appear

"run time error '1004'
application-defined or object-defined error"

But when i delete the (false), all the syntax work like charm


I believe the (false) flag tells Excel not to replace whatever's currently selected with the object you're selecting (I think it only works with worksheets; not sure it works with ranges, etc.). (true) would tell it to select the sheet as the only sheet selected; (false) tells it to keep selecting.
 
Upvote 0
Howdy Oliver (sharp name!), welcome to the board. How's about the following:

<pre>
Sub gram_em()
Dim ws As Worksheet
For Each ws In Sheets
If ws.Visible Then ws.Select (False)
Next
End Sub</pre>
I miss you, Nate.
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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