Deselect first two sheets

G

Guest

Guest
I want to deselect sheets 1 (Master) and 2 (Prep) where I have another 40 sheets also selected in a macro. So as to leave only the 40 sheets selected.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
On 2002-03-08 20:14, Anonymous wrote:
I want to deselect sheets 1 (Master) and 2 (Prep) where I have another 40 sheets also selected in a macro. So as to leave only the 40 sheets selected.

If you have 40 sheets + these 2 then this
may help....

Sub SelectAllSheets()
Dim sh As Worksheet
Dim i As Single

'make sure we Start off with another sheet other then these 2
Do Until ActiveSheet.Name <> "Master" And ActiveSheet.Name <> "Prep"
Sheets(i + 1).Select
i = i + 1
Loop
'Now select all bar 2
For Each sh In ActiveWorkbook.Sheets
If sh.Name <> "Master" And sh.Name <> "Prep" Then
sh.Select False
End If
Next

End Sub


Ivan
 
Upvote 0
Hi

Just to give you a couple more ideas to expand on Ivans answer, try:

Dim sh As Worksheet

On Error Resume Next
For Each sh In ActiveWorkbook.Sheets
sh.Visible = Not (sh.Name = "Master" Or sh.Name = "Prep")
sh.Select False
Next

End Sub
 
Upvote 0
Thanks for that guys. Unfortunately the first two are always selected at the start.

Dave. I see you hide the two sheets, this looks like the better route

Tks
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

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