passwords!!!


Posted by Christopher on January 30, 2001 2:10 PM

Is there a way to password protect a range of "unlocked" cells in a locked worksheet? So, for instance, if I have a series of cells I need to be accessible, but only to a chosen few, but still keeping the "locked-to-all" cells protected.

Posted by Mark Aebi on January 30, 2001 5:16 PM

You have to format the individual cells you don't want to protect and then protect the whole sheet.

Posted by Garland on January 30, 2001 10:54 PM

Christopher,

There is a way to 'password protect' a range of cells. I have created a working example, with macros & explanations. If you would like to review it, let me know via email and I will forward it to you.

Garland

Posted by Mark W. on January 31, 2001 6:43 AM

No.

Posted by Celia on January 31, 2001 1:22 PM


Christopher
Can be done with VBA.
Lock all cells except the ones you want to password protect(cells A1:A3, A5, B1:B2 in the code example below).
Protect the worksheet.
Put the following in the sheet module.
(The password is "allow")

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pwRange As Range, check As String
Set pwRange = Range("A1:A3, A5, B1:B2")
If Not Intersect(Target, pwRange) Is Nothing Then
Application.EnableEvents = False
check = InputBox("Enter password")
If check <> "allow" Then
MsgBox "Password required"
On Error GoTo 1
Application.Undo
Application.EnableEvents = True
Exit Sub
End If
End If
1: Application.EnableEvents = True
End Sub

Posted by Celia on January 31, 2001 1:27 PM

There were a couple of unnecessary lines in the code posted :-

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pwRange As Range, check As String
Set pwRange = Range("A1:A3, A5, B1:B2")
If Not Intersect(Target, pwRange) Is Nothing Then
Application.EnableEvents = False
check = InputBox("Enter password")
If check <> "allow" Then
MsgBox "Password required"
On Error GoTo 1
Application.Undo
End If
End If
1: Application.EnableEvents = True
End Sub

Posted by Celia on January 31, 2001 1:40 PM

Christopher
Please note that the above procedure does not prevent the password protected cells from being changed by dragging the contents from another cell.
To prevent this, a Worksheet_SelectionChange would also need to be added (but this would mean entering the password twice).
Celia



Posted by Kaiowas on February 01, 2001 4:10 AM

Of course, all this assumes your users do not know how to view the source code which contains the password!

Assuming you have a group of 'users' who you want to be able to view the contents of the file but make no changes and also a group of 'authorised users' who are able to modify some cells but are prevented from modifying all of them. Then the best way to achieve this is to do the following:

1) Set the 'Locked' property (Format>Cells>Protection>Locked) for all cells as required (Note that this doesn't actually lock the cells yet!) The default is 'locked' so you will just need to 'unlock' those cells which your authorised users will be able to change.

2) Protect the worksheet (Tool>Protection>Protect Sheet) with a password which only you will know. (This will allow you to modify any cell if required)

3) Save the workbook with a password for write access (File>SaveAs>Options>Password To Modify) This password will be the one you give to your 'authorised users' as it will give them the ability to modify the unlocked cells.

Phil