Thread: Protect Cells
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Protect Cells

Phil

Couple of ways to do this.

1..Lock cells immediately when a name is entered or

2. Lock the cells when you save the workbook.

Method for 1.

Unlock all cells and protect the sheet with a password "justme" or whatever
you choose.

Right-click on sheet tab and "View Code".

Copy/Paste into that module.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 1 Then 'edit to suit
Me.Unprotect Password:="justme" 'edit to suit
n = Target.Row
If Me.Range("A" & n).Value < "" Then 'edit "A" to suit
Me.Range("A" & n).Locked = True
End If
End If
enditall:
Application.EnableEvents = True
Me.Protect Password:="justme"
End Sub

Method for 2.

Unlock all cells. Protect sheet as above.

In Thisworkbook module paste this code.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
Dim rng As Range
Dim rng1 As Range
Dim wksht As Worksheet
Set wksht = Sheets("Sheet1")
wksht.Activate
wksht.Unprotect Password:="justme"
Set rng = Range(Range("A1"), Cells(Rows.Count, 1).End(xlUp))
Set rng1 = rng.Cells.SpecialCells(xlCellTypeConstants)
rng1.Locked = True
wksht.Protect Password:="justme"
End Sub


Gord Dibben MS Excel MVP













On Thu, 14 Jan 2010 18:15:01 -0800, Phil K
wrote:

Is it possible to protect a cell after someone inputs data into it. I want
to develop a sheet where people can sign up for a training session but after
saving the file the cell(s) that have names in them, the cells cannot be
changed.