Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 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.

Stopping the Deletion of Cells

Written by Allen Wyatt (last updated April 6, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

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:

  1. Select the range of cells just to the right of your block you want to protect. In this case, select cells M1:M37.
  2. Type ="" and press Shift+Ctrl+Enter. You've now created a do-nothing array formula that takes the entire range of M1:M37.
  3. Select the range of cells just beneath the block of cells you want to protect. In this case, select cells A38:L38.
  4. Type ="" and press Shift+Ctrl+Enter. You've now created a do-nothing array formula that takes the entire range of A38:L38.

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 Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Stopping the Deletion of Cells.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Pulling Formulas from a Worksheet

The formulas in your worksheet can be displayed (instead of formula results) by a simple configuration change. You can ...

Discover More

Getting Rid of Unused Range Names

Excel allows you to easily create names for different ranges in your workbook. If you ever want to clean up the list of ...

Discover More

Reducing the Size of Spaces in a Selection

If you want to decrease the size of spaces in some selected text, the best approach is to use a macro. This tip includes ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Copying a Cell without Formatting

When you are copying a cell from one place to another (perhaps even to a different worksheet), you may not want to copy ...

Discover More

Forcing Input to Uppercase

If you type information into a workbook, you may want to make sure that what you type is always stored in uppercase. ...

Discover More

Getting Rid of Everything Except Numbers

Got some numbers and letters mixed up in the same cell? You may need to get rid of those letters so you are left with ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2019-08-26 13:22:12

Roy

@Abhay Ghui

Yes, one could go to the row with the arrray formula, or the column, and remove the formula or just delete the cells the array formula is in. One could then start deleting cells in the range one was trying to protect.

So it does not prevent deletion of the important cells. Actually, nothing would, especially as one can open the spreadsheet in some other program which ignores all protection provided by Excel. Google Sheets is an example of that.

What you CAN do and what this does, is give the user who INNOCENTLY, out of some kind of not-thiinking, or just habit, something of a warning that he is not supposed to do this with this particular spreadsheet, or at least this part of it. Obviously, he can just ignore it all, find the array formula, andmess you all up. But remember, he could have done THAT anyway if he so desired.

This would be useful for when the user just needs the reminder that he is not to do that... and that he will comply. Without doing at least this much, giving him that reminder, you just face destruction anyway so it's worth doing.

It all supposes a user who "just forgot I shouldn't do that, Bob, oopsy" and then does not try to overcome it.


2019-08-24 06:53:49

Abhay Ghui

But in this case above we can delete it manually.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.