Closing UserForm that has IF statements within

RMXByker

New Member
Joined
Apr 1, 2010
Messages
38
I have an issue that may be easy for an experienced VBA user. Sorry, I'm just really beginning to sense the power this useful tool has. I need to hide the UserForm once the user has clicked the "Lock" or "Unlock" buttons. I'm sensing there is an issue with the IF statement in the code but I can't seem to come to a conclusion. I've tried a lot of variations of Hide and Unload statements with no success. Hoping someone has an easy fix. Below is the code I currently have. The Lock button unlocks all the sheets in the workbook. Once this is complete, I would like the userform to be hid.

Code:
Private Sub GlobalUnlockButton_Click()
    If GlobalUnlock.Value = "TEST" Then
        For Each Worksheet In ActiveWorkbook.Worksheets
        Worksheet.Unprotect Password:="INFO"
        Next
        Exit Sub
    Else
        MsgBox "You do not have Global Unlock permission"
    End If
    
    Exit Sub
           
End Sub


Private Sub GlobalLockButton_Click()
    If GlobalUnlock.Value = "TEST" Then
        For Each Worksheet In ActiveWorkbook.Worksheets
        Worksheet.Protect Password:="INFO"
        Next
        Exit Sub
    Else
        MsgBox "You do not have Global Lock permission"
    End If
    
    Exit Sub
     
End Sub
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try
Code:
Private Sub GlobalUnlockButton_Click()
    If GlobalUnlock.Value = "TEST" Then
        For Each Worksheet In ActiveWorkbook.Worksheets
            Worksheet.Unprotect Password:="INFO"
        Next
        Me.Hide
    Else
        MsgBox "You do not have Global Unlock permission"
    End If
    
           
End Sub
And the same for the other code
 
Last edited:
Upvote 0
Thank you Fluff. Knew it would be an easy one for a more experienced individual. I think I understand the reasoning with what you did, so thank you greatly!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,724
Messages
6,126,485
Members
449,316
Latest member
sravya

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