Protection

dfenton21

Board Regular
Joined
Jun 23, 2007
Messages
135
Hi All,

Is there a way of preventing a cell from being deleted/altered once text has been typed in.

The user must still be able to enter text into a empty cell (but can't change the cell when finished)

Thanks,
Damien
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi Damien

Protect the sheet with the cells unlocked. Each time the user changes the value of a cell, lock it.
 
Upvote 0
Yes, that's what I meant.

Example.

- Select the sheet cells, format the cells with protection unlocked

- protect the sheet (in this example don't use password)

- paste in the sheet module:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target <> "" Then
    Unprotect
    Target.Locked = True
    Protect
End If
End Sub

Now each time you change the value of a cell it will be locked.
 
Upvote 0
That worked, thanks very much.

I have one other question,

When a user does try to alter a protected cell, is it possible to display a custom message, rather than the standard protection message from Excel.

Thanks,
Damien
 
Upvote 0
When a user does try to alter a protected cell, is it possible to display a custom message, rather than the standard protection message from Excel.

I may be wrong, but I don't think you can change the message.

An alternative is simply do not let the user select locked cells. This way you don't have to worry about the message.

If you want to try it, execute the statement:

Code:
ActiveSheet.EnableSelection = xlUnlockedCells

From now on:

- you will not be able to select locked cells

- if you change the value of an unlocked cell, the Event procedure will lock the cell and excel will automatically select an unlocked cell
 
Upvote 0

Forum statistics

Threads
1,218,920
Messages
6,145,227
Members
450,603
Latest member
jpbegley

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top