ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Code to stop cells being deleted (https://www.excelbanter.com/excel-programming/303419-vbulletin-code-stop-cells-being-deleted.html)

T Jeanes

VB Code to stop cells being deleted
 
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?

Andy Wiggins

VB Code to stop cells being deleted
 
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" <T wrote in message
...
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?




T Jeanes[_2_]

VB Code to stop cells being deleted
 
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.

"Andy Wiggins" wrote:

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" <T wrote in message
...
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?






All times are GMT +1. The time now is 06:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com