Select multiple sheets in VBA based on criterias

Guitarde

Board Regular
Joined
Mar 18, 2003
Messages
244
Hello,

I am trying to select all the sheets that would be included between tab A and tab Z
Essentially same as when selecting manually while holding CTRL

So far this is selecting the right sheet but only one at the time, how can I all sheets between 4 & 9 ?

I do not want to select the sheet, i want to add it to the sheet selection.


Sub Full_set()

'Identify from which sheet to start and where to end
vStart = Sheets("A").Index '4
vFinish = Sheets("Z").Index '9


For Each WS In ThisWorkbook.Worksheets

If WS.Index > vStart And WS.Index < vFinish Then
WS.Select
Else
'WS.Select False
End If

Next WS

End sub


Thanks for your help!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Oh I found my solution, the Select False seems to be doing what I wanted.


Sub Full_set()

'Identify from which sheet to start and where to end
vStart = Sheets("A").Index '4
vFinish = Sheets("Z").Index '9


For Each WS In ThisWorkbook.Worksheets

If WS.Index > vStart And WS.Index < vFinish Then
WS.Select False
Else
'WS.Select False
End If

Next WS

end sub
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,106
Members
452,302
Latest member
TaMere

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