![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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.
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
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 |
|
|
|
|
|
|
#3 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
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 |
|
|
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|