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: Inserting and Deleting Rows in a Protected Worksheet.
Written by Allen Wyatt (last updated September 25, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
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:
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 Microsoft 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.
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!
Want to stop a user from moving or copying a worksheet? This task (like many) can be more complex than one would hope. ...
Discover MoreIt is not unusual, in a corporate world, to be handed a worksheet whose source you don't know. If that worksheet is ...
Discover MoreIf you receive a protected worksheet that you want to edit, how do you proceed if you try to unprotect the worksheet and ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-11-03 13:47:12
Dr. Nick DeBonis
In an Excel workbook on a sheet where nothing is locked. I've been through the old and new procedures. But no matter what I do when I right-click on a cell, column or roll, the DELETE option is open sometimes; however, when you use the right caret, the TABLE COLUMN and TABLE ROWS options are grayed/not active. Ever seen the video of the office worker going postal on the machine?? HYelp? (sic) nick
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments