Macro to unhide all except for. . .

P

Pierre

Looking for a macro to unhide worksheets, except for sheets which I
will define.
Names such as: "Firby", and "Shannon", and "Youngblood", will need to
remain hidden (there are 3 at this time, but that may change). All
others, I'd like to open them with the macro.
This is the code, for starters.. .

Sub UnhideSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
End Sub

Thanks for any thoughts.
Pierre
 
D

Don Guillett Excel MVP

Looking for a macro to unhide worksheets, except for sheets which I
will define.
Names such as: "Firby", and "Shannon", and "Youngblood",  will need to
remain hidden (there are 3 at this time, but that may change). All
others, I'd like to open them with the macro.
This is the code, for starters.. .

Sub UnhideSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
   ws.Visible = xlSheetVisible
Next ws
End Sub

Thanks for any thoughts.
Pierre

if ws.name<>"Firby" and ws.name<>"Shannon" etc
 
D

Dave Peterson

Sub UnhideSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
select case lcase(ws.name)
'type in lowercase!!!
case is = "firby", "shannon", "youngblood"
'do nothing
case else
ws.Visible = xlSheetVisible
end select
Next ws
End Sub
 
D

Don Guillett Excel MVP

Don, could I ask where the statements should go in the code?
Thanks.
Pierre- Hide quoted text -

- Show quoted text -

I would have thought you could have figured that out...

Sub UnhideSheets()
 
P

Pierre

Sub UnhideSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
    select case lcase(ws.name)
       'type in lowercase!!!
       case is = "firby", "shannon", "youngblood"
         'do nothing
       case else
         ws.Visible = xlSheetVisible
    end select
Next ws
End Sub

Thank you Dave and Don. (I appreciate the vote of confidence.) It
works fine.
Best,
Pierre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top