evil_moses
New Member
- Joined
- Oct 27, 2008
- Messages
- 39
Hi all,
I'm new to this forum so be gentle please! Nice to meet you all anyway.
I am trying (very unsucessfully) to write a macro that does the following:
Ask user for a password
If password is correct then hide column J and protect sheet
If ok is selected then exit macro
If password is wrong then display error message.
I am having trouble doing two things.
1. When you press cancel, the error message is displayed instead of just exiting the macro
2. When a wrong password is entered, I want to display the error message and then loop back to the password entry box again.
If you could have a look at my code and help me I would really appreciate it!
Sub Show_Admin_Salary()
'
' Show_Admin_Salary Macro
' Macro recorded 27/10/2008 by Marcus Ponting
'
Dim pw
Dim vbCancel: vbCancel = 2
pw = Application.InputBox("Please enter Password:")
If pw = vbCancel Then
Exit Sub
End If
If pw = "amber1" Then
Sheets("Admin").Select
Dim shtAnySheet As Worksheet
Dim sPassword As String
sPassword = "amber1"
Set shtAnySheet = Worksheets("Admin")
shtAnySheet.Unprotect sPassword
Columns("I:K").Select
Selection.EntireColumn.Hidden = False
Range("A1").Select
Else
MsgBox "Incorrect Password"
End If
End Sub
Thanks a lot
Marcus
I'm new to this forum so be gentle please! Nice to meet you all anyway.
I am trying (very unsucessfully) to write a macro that does the following:
Ask user for a password
If password is correct then hide column J and protect sheet
If ok is selected then exit macro
If password is wrong then display error message.
I am having trouble doing two things.
1. When you press cancel, the error message is displayed instead of just exiting the macro
2. When a wrong password is entered, I want to display the error message and then loop back to the password entry box again.
If you could have a look at my code and help me I would really appreciate it!
Sub Show_Admin_Salary()
'
' Show_Admin_Salary Macro
' Macro recorded 27/10/2008 by Marcus Ponting
'
Dim pw
Dim vbCancel: vbCancel = 2
pw = Application.InputBox("Please enter Password:")
If pw = vbCancel Then
Exit Sub
End If
If pw = "amber1" Then
Sheets("Admin").Select
Dim shtAnySheet As Worksheet
Dim sPassword As String
sPassword = "amber1"
Set shtAnySheet = Worksheets("Admin")
shtAnySheet.Unprotect sPassword
Columns("I:K").Select
Selection.EntireColumn.Hidden = False
Range("A1").Select
Else
MsgBox "Incorrect Password"
End If
End Sub
Thanks a lot
Marcus