Locking the Background Color

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


Mander has a worksheet for which he wants to change the background color. Once changed, he wants the color to be "unchangeable" by anyone else. Mander knows he can use worksheet protection, but that stops people from actually using the worksheet. He doesn't want to stop use of the worksheet; he just doesn't want the background changed once he sets it.

There are a couple of ways you can go about achieving what you want. The first is to examine how you are applying your worksheet protection. The background color is considered a format of a cell, so all you need to do is to make sure you protect the worksheet and allow all changes except to the formatting. Follow these steps:

  1. Select the cells whose contents you want the user to be able to change. (You can select all the cells in the worksheet, if desired.)
  2. Display the Home tab of the ribbon.
  3. Click Format in the Cells group, and then choose Format Cells. Excel displays the Format Cells dialog box.
  4. Make sure the Protection tab is displayed. (See Figure 1.)
  5. Figure 1. The Protection tab of the Format Cells dialog box.

  6. Clear the Locked checkbox.
  7. Click on OK to close the dialog box.
  8. With the Home tab of the ribbon still displayed, click Format in the Cells group, and then choose Protect Sheet. Excel displays the Protect Sheet dialog box. (See Figure 2.)
  9. Figure 2. The Protect Sheet dialog box.

  10. Select all the check boxes except those related to formatting (Format Cells, Format Columns, and Format Rows).
  11. You do not need to enter a password unless you want to; just click on OK.

Now people can make any changes to whatever cells were selected in step 1, with the exception of changing any formatting. This means that your background color remains protected.

There is a problem with this approach—you may want to allow the user to change other cell formatting, such as how numbers, dates, or times are displayed. Since you've protected the formatting of the sheet, however, these things cannot be changed.

To get around this, the only thing you can do is to use a macro-based approach. A simple way is to create an event handler that modifies the background color of the worksheet whenever it is activated. This way, if someone modifies the background color, the next time the worksheet is activated those changes will be effectively done away with. Here's an example that sets the background color to a turquoise color:

Private Sub Worksheet_Activate()
    With Cells.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = RGB(0, 192, 192)
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub

This macro needs to be added to the code sheet for whatever worksheet you want it used with. This particular event handler changes the background of all cells. If you want to affect only a certain number of cells, then you can change the structure (the With structure) so that only specific cells are modified.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (4268) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

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

Sending an E-mail when a Due Date is Reached

Wouldn't it be great if Excel could automatically e-mail you when a due date is reached? It can, if you are using Outlook ...

Discover More

Adjusting Column Widths on Joined Tables

Each table in a document can have different numbers of columns and different widths for columns. If you want to join two ...

Discover More

Removing Add-ins

Add-ins are used to extend Excel's capabilities in lots of different ways. If you want to get rid of an add-in ...

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)

Converting From Numbers to Text

If you have a range of numeric values in your worksheet, you may want to change them from numbers to text values. Here's ...

Discover More

Changing to a Non-US Date Format

Do you want to specify your months and days differently when displaying dates in your worksheets? This tip looks at how ...

Discover More

Changing the Color of a Cell Border

Excel provides a variety of tools you can use to make your data look more presentable on the screen and on a printout. ...

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 less than 9?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.