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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi Damien

Protect the sheet with the cells unlocked. Each time the user changes the value of a cell, lock it.
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
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.
 

dfenton21

Board Regular
Joined
Jun 23, 2007
Messages
135
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
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,186
Messages
5,640,687
Members
417,161
Latest member
Devon150

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
Top