Link to home
Start Free TrialLog in
Avatar of route217
route217Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Add two more worksheet to current code...

Hi Experts

i need to add the following worksheet to function with the vba code below...

1. Payment
2. Telephony...

Sub ToggleVisibilityOfDataWs()

Application.EnableEvents = False

    Const MasterName As String = "Main"
    Const pw As String = "Test1"

        With ThisWorkbook
            If .ActiveSheet.Name = "Main" Then
                With .Worksheets("Source Data")
                    If .Visible Then
                       .Visible = False
                       
                       Else
                       
                       If InputBox("PLEASE ENTER PASSWORD:", "Password Security Check....") = pw Then
                       .Visible = True
                       
                Else
                MsgBox "INCORRECT PASSWORD - PLEASE TRY AGAIN!", vbOKOnly + vbInformation, "Feedback....."
            End If
          End If
         End With
        Else
        
            MsgBox "Can only run this macro from worksheet called " & MasterName, vbOKOnly + vbInformation, "Feedback....."
          End If
        End With
    
    Application.EnableEvents = True
    ActiveWindow.DisplayWorkbookTabs = True

End Sub

Open in new window

Avatar of Shanan212
Shanan212
Flag of Canada image

What are the other worksheets that you want? What are their names?

And

Do you want the new worksheets to be visible if the password is correct?
Avatar of route217

ASKER

worksheet name in above question...

payments and telephony

and yes to the second part. ..
Avatar of Martin Liss
One way is this:

 
If .ActiveSheet.Name = "Main" Or _
    .ActiveSheet.Name = "Payment" Or _
    .ActiveSheet.Name = "Telephony" Then

Open in new window


Another way is

Select Case .ActiveSheet.Name
    Case "Main", "Payment", "Telephony"
        ' do your code
    Case Else
        ' your error message
End Select

Open in new window

SOLUTION
Avatar of Shanan212
Shanan212
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Martinliss

firsty..Thanks for the feedback...but new to this and apologies if this sound rude....but what's the complete code...kindly
thanks shanan212

what can I say...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also change line 5 to

Const MasterName As String = "Main or Payment or Telephony"
I'm glad I was able to help.

Marty - MVP 2009 to 2013