![]() |
Hide/Show some worksheets
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! |
Hide/Show some worksheets
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 Tony S. wrote: 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! -- Dave Peterson |
Hide/Show some worksheets
Dave, as usual, you're a genius. Your code does exactly what I wanted.
Thank you sir. "Dave Peterson" wrote: 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 Tony S. wrote: 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! -- Dave Peterson |
All times are GMT +1. The time now is 05:43 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com