View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default Password Protect a single cell

There are two methods you could use, Dwaine. I think Method 1 works best,
but you can be the judge.

Method 1:
-----------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Address = Range("A10").Address Then
pword = InputBox("Enter Password To Edit State:")
If pword = "Dwaine" Then ActiveCell.Select Else ActiveCell.Offset(1,
0).Select
End If
End Sub

Open your Excel workbook, switch to the VB Editor, select the Sheet object
that contains the cell you want to protect, and paste the above 6 lines of
code into the main work area window. Change the reference to cell €œA10€ in
line 2 to the address of the cell you want to protect and change €œDwaine€ in
the 4th line of code to what ever you want for a password. Save the
workbook; no other action is necessary.

Note that if the worksheet is to be protected for other reasons, the
"Locked" checkbox for the cell's Protection format must be cleared before
protecting the worksheet (this is counter-intuitive, but results in leaner
code and efficient execution (as opposed to adding more code to respond to
the sheet protection).

--------------------


Method 2:
--------------------
Alternatively, if you have Excel2003, try this:

Ensure that the Protection format of the single cell is set to "Locked" (use
Format, Cells, Protection, and check the Locked checkbox). Then, choose
"Tools, Protection, Allow Users to Edit Ranges..." Follow the instructions
there, adding a 'New' range that points to the single cell. Enter a password
for the cell. Don't monkey with the "Permissions..." button unless you are
in a networked environment with shared files.

This should work fine, too. The only problem is that once the cell is
unlocked with the password, it stays unlocked until the file is closed and
reopened.


Good luck and let me know if you have any trouble with this.

Jay




"Dwaine Horton" wrote:

Is there a way to make a user enter a password when they enter a cell? Say I
have a cell that uses data validation to get a list of states. I would like
to make it so that whenever a user clicks or moves to that cell that they
have to enter a password before they can change or select a state.

Thanks

Dwaine