Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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: Forcing a Worksheet to be Protected Again.

Forcing a Worksheet to be Protected Again

Written by Allen Wyatt (last updated May 7, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


3

Barry can lock a worksheet so that only those to whom he gives the password can edit it. If the person enters the password, makes edits, and then saves the workbook containing the worksheet, that worksheet is then unprotected. Barry wonders if there is a way that, when saving the worksheet, Excel can remind the user to once again protect the worksheet using the same password originally used.

There are several ways you can go about solving this problem. If you've assigned a password to a worksheet, then you simply need to make sure that the same password is used to reprotect the worksheet when the workbook is saved. This is easily done by using a macro that can be tied to the BeforeSave event. This macro should be added to the ThisWorkbook object:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Sheets("ABC").Protect ("XYZ")
End Sub

This example assumes that the worksheet you want to protect is named ABC and that the password used to protect the worksheet is XYZ. You'll want to change these values to reflect your actual worksheet and password.

Note that this macro automatically reprotects the worksheet whenever the workbook is saved. Thus, if a user has a long working session with the worksheet and saves the workbook many times during that session, then they will need to unprotect the worksheet quite often. If you prefer, you can create a macro that will ask if the worksheet should be reprotected:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If MsgBox("Reprotect Sheet ABC?", vbYesNoCancel) = vbYes Then
        Sheets("ABC").Protect ("XYZ")
    End If
End Sub

Of course, this approach means that it is possible that a worksheet would not be protected again, if the user chose to not reprotect it.

Another approach doesn't involve using macros at all, but uses a different way to do your protection. In traditional worksheet protection, you format individual cells as unlocked, then you apply protection to the worksheet so that any locked cells cannot be changed. If you don't mark any cells as unlocked (which seems to be what Barry is doing), then nothing in the worksheet can be changed without the password.

Excel actually allows you to protect individual ranges of cells within a worksheet. Follow these steps:

  1. Display the Review tab of the ribbon.
  2. Click Allow Users to Edit Ranges. Excel displays the Allow Users to Edit Ranges dialog box. (See Figure 1.)
  3. Figure 1. The Allow Users to Edit Ranges dialog box.

  4. Click the New button. Excel displays the New Range dialog box. (See Figure 2.)
  5. Figure 2. The New Range dialog box.

  6. In the Title box, enter the name you want to use for this range.
  7. In the Refers to Cells box, enter the range you want users to be able to edit. (If there are multiple ranges you want to use this same password, you can separate those ranges with a comma.)
  8. In the Range Password box, enter the password you want to give to your users.
  9. Click on OK. You are again asked to enter the password.
  10. Enter the password you used in step 6 a second time. The range now appears in the Allow Users to Edit Ranges dialog box.
  11. Click OK to close the Allow Users to Edit Ranges dialog box.
  12. Protect your worksheet as you normally would.

There is only one thing you need to remember when you protect your worksheet (step 10). Since you've not unlocked any cells, then all cells in the worksheet will be protected. You need to make sure that the protection you apply allows locked cells to be selected. If, after the worksheet is protected, a user tries to edit a cell that is in the range you specified in step 5, they are asked for the password you specified in step 6. When they provide it, they can make edits to any cells in the range.

The cool thing about this approach is that worksheet protection is not removed—the worksheet is still protected because the user never removed that protection. Thus, the user never needs to know the password for the entire worksheet. When the user closes and reopens the workbook, the worksheet is still protected, just as you need. Plus, you don't have the unavoidable downside of macros—that they can be disabled by a user when they open the workbook.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11973) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Forcing a Worksheet to be Protected Again.

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

Hiding Smart Tags

If you don't want to see Smart Tags displayed in your document, you can instruct Word to hide them. Here's how to make ...

Discover More

Copying a Hyperlink to Lots of Worksheets

Copying information from one place to another in a worksheet is easy. Copying hyperlinks may not seem that easy, but you ...

Discover More

Understanding the COMPARE Field

The COMPARE field is rather esoteric, but it can be helpful when you need to compare two values using fields. The result ...

Discover More

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!

More ExcelTips (ribbon)

Protecting Many Worksheets

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

Discover More

Protecting Worksheets from Deletion

If you share a workbook with others in your office, you will probably want to make sure that some of the worksheets don't ...

Discover More

Visually Showing a Protection Status

Need to know if a worksheet or workbook is currently protected? Excel provides some tell-tale signs, but here are some ...

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 two more than 7?

2022-05-08 02:38:59

Steve

Allan,

Is there a “before close’ alternative to “before save’ which gets around the issue of in session saving?

Steve


2022-05-07 07:40:09

Philip

Why not put this macro in a "BeforeClose" event of the workbook? that way, the user can save as many times they want during a long session, but the protection will only be re-activated when really "closing" the workbook ...


2022-05-07 05:43:45

Keebellah

And why not include the parameter 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.