Seamus2626
asked on
Pass word protect named ranges
Hi,
I have a list of names and columns of data, i am going to name all these ranges
I would like some code that if you click anywhere in that named range you get prompted to enter a password that i can nominate
Has anyone got such code?
Thanks
Seamus
I have a list of names and columns of data, i am going to name all these ranges
I would like some code that if you click anywhere in that named range you get prompted to enter a password that i can nominate
Has anyone got such code?
Thanks
Seamus
Small hint for using Kyle's solution:
You'll ideally want to protect the VBProject and the workbook itself with a password too, otherwise nothing's stopping the users from hitting ALT+F11 and looking at the code to find the right password.
You'll ideally want to protect the VBProject and the workbook itself with a password too, otherwise nothing's stopping the users from hitting ALT+F11 and looking at the code to find the right password.
Here's an updated version. I made the assumption that as soon as someone entered the correct password they should be allowed to keep working in the range until they clicked outside the boundaries. At that point they will need to enter the password again to re-enter the range. You will need to specify a cell into which the code can dump a variable. In the example I used "I2". Modify as necessary.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim PWord As String
PWord = "MyPassword"
If Not Application.Intersect(Range("rngTemp1"), Target) Is Nothing Then
If Range("I2") <> "r1" Then
If Not PWordIsCorrect(PWord) Then Range("A1").Select Else Range("I2") = "r1"
End If
ElseIf Not Application.Intersect(Range("rngTemp2"), Target) Is Nothing Then
If Range("I2") <> "r2" Then
If Not PWordIsCorrect(PWord) Then Range("A1").Select Else Range("I2") = "r2"
End If
ElseIf Not Application.Intersect(Range("rngTemp3"), Target) Is Nothing Then
If Range("I2") <> "r3" Then
If Not PWordIsCorrect(PWord) Then Range("A1").Select Else Range("I2") = "r3"
End If
Else
Range("I2") = "Nothing"
End If
End Sub
Function PWordIsCorrect(sPass As String) As Boolean
Dim s As String
s = InputBox("Enter the password", "Password required")
If s = sPass Then PWordIsCorrect = True Else PWordIsCorrect = False
End Function
Kyle
ASKER
That looks really good Kyle, but i need each range to have a different password, not one password for the whole lot
Thanks
Seamus
Thanks
Seamus
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much Kyle, thanks too DaFranke, i will lock the project
Cheers,
Seamus
Cheers,
Seamus
You're welcome. Glad to help.
Kyle
Kyle
Open in new window
KyleQ-27648596-RevA.xlsm