Input information in cell but once input no one can delete?

Imran

Board Regular
Joined
Apr 1, 2003
Messages
66
Is there anyway i can protect a cell as soon as some information has been inputted into it thus people can not delete the information they have just typed?

(i want this done automatically and not by using the Tools>Protection afterwards)

Regards
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You would have to use a macro, and all the macro would do is the equivalent of Tools>Protection.

For instance:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'unprotect the sheet
ActiveSheet.Unprotect

'change the cell(s) that were changed to 'Locked'
Target.Locked = True

'protect the sheet
ActiveSheet.Protect

End Sub
 
Upvote 0
You could leave the cells that can be changed unlocked and lock the rest of the cells and then protect the sheet. Then use some worksheet change event code to unprotect the sheet, lock the cell that was just changed, then protect the sheet. It may look something like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Sheets("Sheet1").Unprotect
    Target.Locked = True
    Sheets("Sheet1").Protect
End Sub

Note that this is untested on my part and you will have to make sure that the wrong cells are not already locked, you can also add password like so....

Sheets("Sheet1).Protect("YourPasswordHere")
of course then you will need the password in the unprotect line in the same fashion.

Hope this is helpful!
 
Upvote 0
Thanks for the help, this works perfect for one cell, How can i do this for each cell? in that after the first cell is protected i click into another cell which then gets unprotected i then input my data and this then gets reprotected.

Regards
 
Upvote 0
The code will work for every cell on the sheet. The Target variable will refer to whatever cell(s) have been changed. It is dynamic.

If you want to be able to enter into any cell to begin with, you should make sure all of the cells are unlocked. That way when the sheet is protected if you make a change, only the cells you changed will be locked and the others should still be available to edit.

So, do this:
- Unprotect the sheet (if needed)
- Ctrl+A (selects all cells on the sheet)
- Format->Cells->Protection tab
- Uncheck the box next to "Locked."
- Click OK

All cells on that sheet should now be unprotected. When you edit a cell, the macro should kick in and then lock only those cells you changed, and then protect the sheet so that those cells can no longer be changed.

Edit: There is a difference in the code I posted and the code Brian posted, though. My code will work only on the active sheet (the one you make the changes on). Brian's code will only unprotect a sheet named "Sheet1"--it will not matter whether that is the active sheet or not.
 
Upvote 0
Edit: There is a difference in the code I posted and the code Brian posted, though. My code will work only on the active sheet (the one you make the changes on). Brian's code will only unprotect a sheet named "Sheet1"--it will not matter whether that is the active sheet or not.
That is a very good point... I had thought I mentioned that in the post but I obviously did not.
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,223
Members
453,152
Latest member
ChrisMd

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