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 does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,140
Messages
6,123,269
Members
449,093
Latest member
Vincent Khandagale

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