djrobr199
New Member
- Joined
- Sep 2, 2011
- Messages
- 2
I have a command button that will delete multiple ranges and I have it password protected. All of my sheets are password protected so I have it automatically unprotecting the sheet and supplying a new password so that it would prompt the user to enter the new password (which they will know) in order for them to clear the ranges (to prevent accidental clearing of data), then it would protect the sheet with the original password when all the ranges have been cleared. The problem i'm running into is that if the user selects the command button and then selects the cancel button or red X to close out (if they selected it by mistake) it still clears out the ranges. If they select OK without entering a password then all the data remains as it should (via the error handling). Is there a way to fix this problem?
(# represents my password that the user does not have access to)
(@ represents the password that the user will know)
Private Sub CommandButton5_Click()
' clear out all unit counts and yard count clear time
On Error GoTo errorfound
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="######"
ActiveSheet.Protect Password:="@@@@@@@"
ActiveSheet.Unprotect
Range("E6:E9").Select
Selection.ClearContents
' There are many more ranges but removed them to make this post smaller
Range("A5").Select
Selection.ClearContents
ActiveSheet.Protect Password:="######"
Application.ScreenUpdating = True
Range("E6").Select
errorfound:
Sheets("master count input").Select
ActiveSheet.Unprotect Password:="@@@@@@@"
ActiveSheet.Protect Password:="######"
End Sub
(# represents my password that the user does not have access to)
(@ represents the password that the user will know)
Private Sub CommandButton5_Click()
' clear out all unit counts and yard count clear time
On Error GoTo errorfound
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="######"
ActiveSheet.Protect Password:="@@@@@@@"
ActiveSheet.Unprotect
Range("E6:E9").Select
Selection.ClearContents
' There are many more ranges but removed them to make this post smaller
Range("A5").Select
Selection.ClearContents
ActiveSheet.Protect Password:="######"
Application.ScreenUpdating = True
Range("E6").Select
errorfound:
Sheets("master count input").Select
ActiveSheet.Unprotect Password:="@@@@@@@"
ActiveSheet.Protect Password:="######"
End Sub