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: Inserting and Deleting Rows in a Protected Worksheet.

Inserting and Deleting Rows in a Protected Worksheet

by Allen Wyatt
(last updated October 23, 2018)

7

When you protect a worksheet, Excel allows you to define what the user can do in that protected worksheet. Using the check boxes in the Protect Sheet dialog box, you can choose a wide variety of allowed actions. (See Figure 1.)

Figure 1. The Protect Sheet dialog box.

One of the actions allowed in the Protect Sheet dialog box is inserting and deleting rows and columns in a protected worksheet. This is a great feature for some types of worksheets. But there is something odd in how this feature actually works.

Let's say you create a worksheet and you protect it. In doing so, you indicate that it is OK for people to both insert and delete rows in the protected worksheet. When someone tries to insert a row in the protected worksheet, it inserts just fine. If someone tries to delete a row—even the row they just inserted—the action is not allowed; it cannot be done. What gives? You indicated in the Protect Sheet dialog that people could delete rows, but still Excel doesn't allow you to do so.

The reason seems to be tied to how Excel implements worksheet protection. Remember that protection is applied to all cells that are formatted as Locked on the Protection tab of the Format Cells dialog box. If any cell in a row you try to delete is formatted as Locked, then worksheet protection won't allow you to delete the row. If all the cells in the row have the Locked check box cleared, then the row can be successfully deleted. (See Figure 2.)

Figure 2. The Protection tab of the Format Cells dialog box.

Interestingly, the user cannot delete a row that they added because the added row inherits the cell formatting of the row above it. So, if there are any locked cells in the row above the row inserted, then the inserted row cannot be deleted as long as the worksheet is protected.

This behavior, of course, is not terribly useful for any worksheet developer that really wants people to have the ability to delete rows in a worksheet, regardless of whether cells in the rows are locked. If you are one of those people, then the only thing you can do is create a macro that does the deletion for you. The macro must accomplish the following steps:

  1. Unprotect the worksheet
  2. Delete the row
  3. Protect the worksheet again

These three steps are relatively easy to perform, using techniques described in other issues of ExcelTips. To make the macro useful, you will probably want to add code that ensures the user isn't trying to delete rows you don't want them to delete (headings, totals, etc.).

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10315) 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: Inserting and Deleting Rows in a Protected Worksheet.

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

Temporarily Changing the Printer in a Macro

You can use a macro to print to any printer you have defined in Windows. It is good practice, if you are changing which ...

Discover More

Auto Creation of an Acronym List

If you use a lot of acronyms in your documents, you may want a quick way to compile those acronyms and their definitions ...

Discover More

Adding a File Path and Filename

If you need to stuff the current workbook's filename and path into a cell or a header or footer, you'll appreciate the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Enabling Editing Erases Worksheet

If you receive a protected worksheet that you want to edit, how do you proceed if you try to unprotect the worksheet and ...

Discover More

Protecting Many Worksheets

Need to protect a lot of worksheets? Rather than protect the sheets individually, you'll appreciate the macros discussed ...

Discover More

Forcing a Worksheet to be Protected Again

Excel allows you to protect your worksheets so they can only be changed as you want to have happen. If you unprotect a ...

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}] 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 - 8?

2018-10-23 11:52:51

David Gray

I have encountered this from time to time in my own worksheets. However, since I have the protection passphrase, I just worked around it. On reflection, the explanation makes complete sense, which made this tip absolutely worth the tome it took me to read it.


2016-11-02 12:46:48

Deborah

My cells are unlocked in a table, but I still cannot delete the rows after protection. This is a form for people to change the rows at will.


2015-06-14 07:09:29

Md.Khorshed

how to excel sheet 1 lock doesn't delete?


2015-05-30 06:42:11

NEHA KULKARNI

your article is useful buy it is not mentioned here that what if the excel is protected with a password? please give me information about it.


2015-05-27 04:49:06

James

The other outcome of this is that the new cells inserted do not inherit the formulae of the protected ones above - half my columns are unprotected (for dropping data into) and half are not (for formulae which acts on the data) - is there anyway around this - I don't want anyone to be able to change the formulae but I do want the formulae to work when data is added to the unprotected columns.


2015-03-04 05:17:32

Eulogio Castillo

I want to protect only specified column
example column C & D etc.. can you please send me how because I try these to many times I can not get it


2015-03-03 10:13:14

Robert Beard

If you protect the worksheet as follows in the Workbook_Open proc, then you don't have to Unprotect and then reprotect the worksheet when doing the delete in a macro.

Example: Sheets("Notes").Protect UserInterFaceOnly:=True


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.