Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Stopping the Deletion of Cells.
by Allen Wyatt
(last updated August 1, 2015)
Vilas knows that he can protect a worksheet so that users cannot delete cells. However, he has a need to prevent the deletion of cells without using worksheet protection. (Vilas is not talking about the clearing of cell contents, but the actual deletion of cells so that surrounding cells must move left or move up.) He wonders if there is a way to prevent a user from deleting cells, without protecting the worksheet.
There is no direct way to do this in Excel. It would be nice if Excel provided a way to create an event handler that was called whenever a cell was deleted, but it does not. (The Worksheet_Change event is apparently triggered whenever the contents of a cell are changed, but not when a cell is entirely deleted.) Because of this, using a macro to protect your cells from being deleted is not the way to go.
The best solution we've been able to find involves taking advantage of a quirk in how Excel handles array formulas. For the sake of example, let's assume that you have data in the range A1:L37, and you don't want any cells within this range to be deleted. Follow these general steps:
At this point you cannot delete any cell within the data block (A1:L37), nor can you delete any row 1 through 37 or any column A through L. Whenever you try, Excel displays a message that says "You cannot change part of an array." The only way to delete cells, rows, or columns within the data block is to first get rid of the array formulas that would be affected. In other words, you would need to delete column M or row 38 first.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10255) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Stopping the Deletion of Cells.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Got a list of data from which you want to delete duplicates? There are a couple of techniques you can use to get rid of the ...Discover More
Want to delete a bunch of rows in a worksheet based on the value in a certain cell of each row? There are a couple of ways ...Discover More
If you need to often delete duplicate items from a list, then you'll love the macro presented in this tip. It makes quick ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.