VB Code to stop cells being deleted

T

T Jeanes

I would like to write some VB code to stop users deleting the contents of cells in excel. The cells need to be unprotected as users need to input values in them, however, they have formulas in which link to a database. If a user presses the delete button they will remove the formula.

I need to write some code which activates when the delete button is hit. I have written some code, however, can only get it to activate when a button is clicked.

Can anyone help?
 
A

Andy Wiggins

How can they input values unless they directly edit the formula?

If your users do actually edit the formula then I suggest you change your
input routine.
Make the input cells values only (which you can leave unlocked) and make
references in the formulas to those cells (which can be locked).

--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"



T Jeanes said:
I would like to write some VB code to stop users deleting the contents of
cells in excel. The cells need to be unprotected as users need to input
values in them, however, they have formulas in which link to a database. If
a user presses the delete button they will remove the formula.
I need to write some code which activates when the delete button is hit. I
have written some code, however, can only get it to activate when a button
is clicked.
 
T

T Jeanes

Thanks for your help. Excel is just the front end of an external database and thus the formulas in the cells relate to references to the database. i.e. when somebody enters 10 they are actually writing 10 to the database.

I need a macro which is running in the backround, like a worksheet event, that will detect if a user hits the delete button. If they press delete I want a message box to appear asking them to instead enter 0.
 
Top