Hide/Show some worksheets

T

Tony S.

Is there a way to use VB code to hide/show a group of worksheets at once,
possibly using a wildcard? I have a worksheet that contains many sheets that
need to be Veryhidden or Visible easily without having to go
thru the Format/Sheet/Hide menu. Each worksheet is named for a week of the
year. (i.e. "(Wk 1) 12-1-2008", "(Wk 2) 12-8-2008", "(Wk 3) 12-15-2008"
etc). The
current week named "Current Status" will always be visible. Idealy if a
wildcard for any worksheet containing "Wk" could be used would work great.
Thanks!
 
D

Dave Peterson

Option Explicit
Sub testme()
Dim sh As Object

'make sure that there's always one sheet visible first
Worksheets("Current status").Visible = xlSheetVisible

For Each sh In ActiveWorkbook.Sheets
If LCase(sh.Name) = LCase("current status") Then
'skip it
Else
If LCase(sh.Name) Like LCase("wk*") Then
sh.Visible = xlSheetHidden
End If
End If
Next sh
End Sub
 
T

Tony S.

Dave, as usual, you're a genius. Your code does exactly what I wanted.
Thank you sir.
 

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