View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Mark Mark is offline
external usenet poster
 
Posts: 989
Default sheets(array).select problem

I've tried various formats of array contents in sheets(array).select, and
always get a subscript out of range error. I've used (1, 2, 3), ("sheet1",
"sheet2", "sheet3"), and others. I DO have multiple sheets, and have
verified that the ones in the array actually exist.

My current code:

Dim mySheet As Worksheet

For Each mySheet In ActiveWorkbook.Sheets

Worksheets(mySheet.Name).Activate

If ActiveSheet.Tab.ColorIndex = 3 Then 'this is a red tab worksheet

If sheetlist = "" Then
sheetlist = mySheet.Index
Else
sheetlist = sheetlist & ", " & mySheet.Index
End If

End If

Next

Sheets(sheetlist).Select

End Sub

Sheetlist contents when it crashes on select statement:

31, 32, 33, 36

But it crashes if I change the code so that sheetlist contents a

"sheet31, "sheet32", "sheet33", "sheet36"