O
OssieMac
I want to do the following but with a variable number of worksheets.
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
or the following.
Sheets(Array(1, 2, 3)).Select
I found similar code to the following from this forum and it was checked as
an answer but I am not having any success. See the comment in the code for
the error.
Sub SelectMultipleSheets()
Dim intShtsCount As Integer
Dim shtArray()
Dim i As Integer
intShtsCount = ActiveWorkbook.Sheets.Count
ReDim shtArray(intShtsCount)
For i = 0 To intShtsCount - 1
shtArray(i) = Sheets(i + 1).Name
Next i
'*******************************
'Following line returns runtime error '9' Subscript out of range
'********************************
Sheets(shtArray).Select
End Sub
All help appreciated.
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
or the following.
Sheets(Array(1, 2, 3)).Select
I found similar code to the following from this forum and it was checked as
an answer but I am not having any success. See the comment in the code for
the error.
Sub SelectMultipleSheets()
Dim intShtsCount As Integer
Dim shtArray()
Dim i As Integer
intShtsCount = ActiveWorkbook.Sheets.Count
ReDim shtArray(intShtsCount)
For i = 0 To intShtsCount - 1
shtArray(i) = Sheets(i + 1).Name
Next i
'*******************************
'Following line returns runtime error '9' Subscript out of range
'********************************
Sheets(shtArray).Select
End Sub
All help appreciated.