muhleebbin
Active Member
- Joined
- Sep 30, 2017
- Messages
- 252
- Office Version
- 365
- 2019
- 2016
- 2013
- 2010
- Platform
- Windows
- MacOS
- Mobile
- Web
Hi everyone,
I have the following code that works well for what I need it to do however do need to tweak it a slight bit to view a certain set of sheets. Right now I have sheets PP##, PP## Mod, PP## LD, PP## Pivot, and PP## Override and the ##'s go through 01 - 27 so there's literally 135 sheets plus several others. YTD Daily and YTD Monthly will never be hidden and the drop down menu that selects what sheets are viewed are in YTD Daily. At the moment there's options to select PP01 - PP27, LD and override, so if you select PP03 it will show YTD Daily, YTD Monthly and any PP03 sheet and similarly for any selection. I'd like to create a summary selection where it will show YTD Daily, YTD Monthly and any PP## sheet but not the others (Mod, LD, Pivot or Override). Is there a way to modify this code to base the hide/unhide on the number of characters?
Thanks in advance for your assistance!
I have the following code that works well for what I need it to do however do need to tweak it a slight bit to view a certain set of sheets. Right now I have sheets PP##, PP## Mod, PP## LD, PP## Pivot, and PP## Override and the ##'s go through 01 - 27 so there's literally 135 sheets plus several others. YTD Daily and YTD Monthly will never be hidden and the drop down menu that selects what sheets are viewed are in YTD Daily. At the moment there's options to select PP01 - PP27, LD and override, so if you select PP03 it will show YTD Daily, YTD Monthly and any PP03 sheet and similarly for any selection. I'd like to create a summary selection where it will show YTD Daily, YTD Monthly and any PP## sheet but not the others (Mod, LD, Pivot or Override). Is there a way to modify this code to base the hide/unhide on the number of characters?
Thanks in advance for your assistance!
VBA Code:
Sub HideShowSheets()
Dim wb As Workbook
Dim ws As Worksheet
Dim arr As Variant
Dim t As String
Dim i As Integer
Dim y As Integer
Set wb = ThisWorkbook
If wb.Worksheets.Count = 1 Then
MsgBox "Workbook only contains one worksheet that cannot be hidden.", vbOKOnly, "Warning!"
Exit Sub
End If
t = Worksheets("Lists").Range("BY1")
ReDim arr(2, wb.Worksheets.Count)
For i = 1 To wb.Worksheets.Count
arr(1, i) = wb.Worksheets(i).Name
If InStr(1, wb.Worksheets(i).Name, t) > 0 Then arr(2, i) = True
Next
On Error Resume Next
For y = 1 To wb.Worksheets.Count
Set ws = wb.Worksheets(arr(1, y))
'Show Worksheets that meet the criteria
If arr(2, y) Then
If Not ws.Visible Then ws.Visible = True
End If
'Hide Worksheets that do not meet the criteria except for "YTD"
If Not arr(2, y) And Not ws.Name = "YTD Daily" And Not ws.Name = "YTD Monthly" Then
If ws.Visible Then ws.Visible = False
End If
Next
On Error GoTo 0
Sheets("YTD Daily").Activate
ActiveSheet.Range("A1").Select
End Sub