Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50142

Unhide or hide sheets based on drop down list value - need help combining these two macros

$
0
0
I'm trying to incorporate these these macros into one where the drop down value would unhide any sheet name starting with that value. I'd also like for it to be an Open Workbook event so that when the workbook is reopened the selected values will stay in place. This is important because there is another macro forcing a user to enable macros that unhides all sheets when the workbook opens.

Macro1

Code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Me.Range("drop down list value").Address Then
    If Target.Value = "2nd" Then
        Sheets("any sheet name starting with 2nd...").Visible = True
    Else
        Sheets("any sheet name starting with 2nd...").Visible = False
    End If
End If
End Sub

The above needs to be combined with the below:


Code:

Private Sub CommandButton1_Click()
' Unhides all sheets starting with 2nd
Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        If Left(ws.Name, 3) = "2nd" Then
                ws.Visible = xlSheetVisible
            End If
    Next ws
End Sub

Thanks for any help.

Viewing all articles
Browse latest Browse all 50142

Trending Articles