Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Stopping the Deletion of Cells.
by Allen Wyatt
(last updated August 24, 2019)
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 (10256) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Stopping the Deletion of Cells.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
When you create a worksheet, it is common to place headings at the top of each column and the left of each row so you can ...Discover More
Need to get rid of everything in a worksheet except for your formulas? You can do it rather easily by applying the ideas ...Discover More
When you are entering information in a worksheet, it sure would be handy to have a way to "mask" the information being ...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 ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.