VBA Select all sheets in between

domtrump

Board Regular
Joined
Apr 1, 2010
Messages
245
I have a workbook in which I need to select multiple sheets using VBA. The start sheet always has the same name and the end sheet always has the same name. However, there could be from 1 to 12 sheets in between with varying names (as well as some sheets after the end sheet or before the start sheet).

How can I select all the sheets in between start and end (including start and end) no matter how many are in the middle?

Thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Code:
Sheets(Evaluate("TRANSPOSE(ROW(" & Sheets([SIZE=3][COLOR=#ff0000][B]"Start"[/B][/COLOR][/SIZE]).Index + 1 & ":" & Sheets([SIZE=3][COLOR=#ff0000][B]"End"[/B][/COLOR][/SIZE]).Index - 1 & "))")).Select

Change the name of the sheets in bold
 
Upvote 0
Code:
Sub Select_Middle_Sheets()

If Sheets.Count < 3 Then Exit Sub

Dim myArr() As String
ReDim myArr(Sheets.Count - 3)

For i = 2 To Sheets.Count - 1
    myArr(j) = Sheets(i).Name
    j = j + 1
Next i

Sheets(myArr).Select
Sheets(2).Activate
    
End Sub
 
Upvote 0
One more way...
Code:
Sub SelectSheetsBetweenStartAndEnd()
  Dim X As Long
  ActiveSheet.Select
  For X = Sheets("Start").Index + 1 To Sheets("End").Index - 1
    Sheets(X).Select False
  Next
End Sub
 
Last edited:
Upvote 0
One more way...
Code:
Sub SelectSheetsBetweenStartAndEnd()
  Dim X As Long
  ActiveSheet.Select
  For X = Sheets("Start").Index + 1 To Sheets("End").Index - 1
    Sheets(X).Select False
  Next
End Sub

That got me close. I made the mods below to capture both the start and end sheets and make sure it didn't matter which sheet the user was on when the macro was run. Thanks for the help!

Code:
Sub SelectSheetsBetweenStartAndEnd()
  Dim X As Long
  Sheets("Start").Select
  For X = Sheets("Start").Index + 1 To Sheets("End").Index
    Sheets(X).Select False
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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