This worked for me. If you still get a subscript out of range error, then
post the code as you have it and list the sheets in the order they appear in
your workbook.
Sub GroupSheets()
Dim sh As Object
Dim shArr() As String
Dim FirstSheet As Object
Dim LastSheet As Object
Set FirstSheet = Sheets("Sheet2")
Set LastSheet = Sheets("Sheet4")
If FirstSheet.Index > LastSheet.Index - 2 Then
MsgBox "First sheet must be less than Last sheet"
Exit Sub
End If
ReDim shArr((FirstSheet.Index + 1) To (LastSheet.Index - 1))
For Each sh In ThisWorkbook.Sheets
If sh.Index > FirstSheet.Index And sh.Index < LastSheet.Index Then
shArr(sh.Index) = sh.Name
End If
Next sh
Sheets(shArr).Select
End Sub
--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel www.dicks-blog.com
Carol said:
ALso I might add this should be non inclusive of sheet2 and sheet3...Index
I set up a workbook with all of the sheets you listed. I then copied and
pasted the code into a standard module. When I ran the code, it selected
all the sheets between Start and End.
I'm at a loss as to why it won't work for you. I can send you my workbook
or you can send me yours and maybe we can see what the difference is.
What version of Excel are you using? It shouldn't matter, but I'm grasping
at straws at this point.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.