Select an array of worksheets VBA

J

Jamuck

I am trying to write a macro that will select an array of worksheets.
The number of worksheets may vary from book to book so I tried usin
the following:
Sheets(Array("Sheet (1)", Sheets(Sheets.Count))).Select

but this doesn't work. Can anyone help me out please:confused
 
A

Ardus Petus

Sheets(Array(Sheets(1).name, Sheets(Sheets.Count).name)).Select

Will select 1st and last worksheets

HTH
 
J

Jamuck

Thanks for that. Is it possible to select a range of worksheets ie fro
say the second sheet to the last
 
D

Dave Peterson

One way:

Dim iCtr As Long
With ActiveWorkbook
For iCtr = 2 To .Sheets.Count
.Sheets(iCtr).Select Replace:=CBool(iCtr = 2)
Next iCtr
End With
 
J

Jamuck

Thanks Dave but I pasted in the code you gave and it returned an error.
I understand all that you wrote except for the 'replace' statement which
I guess is the key to it.
 
D

Dave Peterson

Replace will specify whether you want the sheet selected by itself or added to
the group of selected sheets.

If it didn't work for you, you'll have to post the code you used and the actual
error you received.
 
Top