Macro to hide/unhide all Purple Tabs with password needs simplifying

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have this macro that when run asks for a password then hides or unhides all purple tabs,
it works great but I only really need it to ask for a password if we are unhiding the sheets?

Can anyone edit or redo this macro so when run if the Purple tabs are visible it veryhides them but if they are hidden it asks for a passwrd then unhides them if the password is correct?
thanks

Tony

heres my code

VBA Code:
Sub Hide_unhide_Purple_Sheets()
TABCOLOR2 = RGB(112, 48, 160) 'Purple
Dim ws As Object

Application.ScreenUpdating = False
 x = InputBox("Enter Password", "")
If x = "august" Then


For Each ws In ActiveWorkbook.Worksheets
If ws.Tab.Color = TABCOLOR2 Then
If ws.Visible = xlSheetVisible Then
ws.Visible = xlSheetVeryHidden
Else
ws.Visible = xlSheetVisible
End If
End If
Next ws

Else
For Each ws In ActiveWorkbook.Worksheets
If ws.Tab.Color = TABCOLOR2 Then
ws.Visible = xlSheetVeryHidden
End If

Next ws

End If
NewReport1.Activate
Application.ScreenUpdating = True


End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
hi,
see if this update to your code does what you want

VBA Code:
Sub Hide_unhide_Purple_Sheets()
    Dim ws              As Object
    Dim x               As Variant
    Dim TABCOLOR2       As Long
    Dim strPrompt       As String
    
    Const strPassword   As String = "august"
    
    TABCOLOR2 = RGB(112, 48, 160) 'Purple
  
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Tab.Color = TABCOLOR2 Then
            If Not ws.Visible And x <> strPassword Then
                x = InputBox("Enter Password", "Enter Password")
                'cancel pressed
                If StrPtr(x) = 0 Then Exit Sub
                If x <> strPassword Then MsgBox "Invalid Password", 48, "Invalid": Exit Sub
            End If
            Application.ScreenUpdating = False
            ws.Visible = IIf(x = strPassword, xlSheetVisible, xlSheetVeryHidden)
        End If
    Next ws
    
    NewReport1.Activate
    Application.ScreenUpdating = True
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top