Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Locking All Non-Empty Cells.

Locking All Non-Empty Cells

by Allen Wyatt
(last updated September 28, 2017)

4

Sandeep has a worksheet that has hundreds of rows and columns. Some of the cells have information in them and some are empty. The empty cells are used for data entry. He would like a way to easily lock all the non-empty cells in a selected range and then lock the worksheet.

This is rather easy to do manually. There is an important item to keep in mind, however: All the cells in the worksheet are "locked," by default. In other words, you don't need to look for a way to lock the non-empty cells; you only need to look for a way to unlock the empty ones. (There is one exception to this, addressed shortly.)

With this in mind, you can follow these steps to get your empty cells unlocked:

  1. Select the range you want to affect.
  2. Press F5. Excel displays the Go To dialog box. (See Figure 1.)
  3. Figure 1. The Go To dialog box.

  4. Click Special. Excel displays the Go To Special dialog box. (See Figure 2.)
  5. Figure 2. The Go To Special dialog box.

  6. Select the Blanks radio button.
  7. Click OK.
  8. Press Ctrl+1. Excel displays the Format Cells dialog box.
  9. Make sure the Protection tab is selected. (See Figure 3.)
  10. Figure 3. The Protection tab of the Format Cells dialog box.

  11. Clear the Locked check box.
  12. Click OK.

That's it. You can now lock your worksheet and only those blank cells that were selected at the end of step 5 will be accessible.

One interesting thing to note is that you don't really have to select a range in step 1. If, instead, you select a cell within the main body of your worksheet's entries, Excel assumes that you want to operate on the used area of your worksheet. In other words, when you get to step 5 what will be selected are all the empty cells in the used area of you worksheet.

One more thing to be aware of is that once you set the locking status of a cell (step 8), the cell retains that status until you specifically change it. This means that if you've previously made changes to the locking status of the cells, it may be beneficial to explicitly lock the cells prior to unlocking the empty ones. You can do this by following these modified steps:

  1. Select the range you want to affect.
  2. Press Ctrl+1. Excel displays the Format Cells dialog box.
  3. Make sure the Protection tab is selected.
  4. Make sure the Locked check box is selected.
  5. Click OK.
  6. Press F5. Excel displays the Go To dialog box.
  7. Click Special. Excel displays the Go To Special dialog box.
  8. Select the Blanks radio button.
  9. Click OK.
  10. Press Ctrl+1. Excel displays the Format Cells dialog box.
  11. Make sure the Protection tab is selected.
  12. Clear the Locked check box.
  13. Click OK.

In this case you must perform step 1—you have to select a range to affect. Excel won't assume which range you want to affect as in the earlier comment.

If you prefer, you can use a macro to protect your cells and your worksheet:

Sub UnlockEmptyCells()
    Dim myCell As Range

    Set myCell = Selection
    Cells.Select
    Selection.Locked = True
    myCell.Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.Locked = False
    
    ActiveSheet.Protect DrawingObjects:=True, _
      Contents:=True, Scenarios:=True
    myCell.Select
End Sub

This macro makes sure that all the cells in the worksheet are locked, then it unlocks the blank cells in the used range, and finally it protects the worksheet.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8485) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Locking All Non-Empty 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

Formatting Currency

If you need to format a number so that it appears as currency, it is not as easy to do in Word as it is in Excel. You can use ...

Discover More

Changing a Toolbar Button Image

Excel allows you to modify virtually all aspects of its user interface. One of the things you can change is the images used ...

Discover More

Ignoring Selected Words when Sorting

If you use Excel to maintain a list of text strings (such as movie, book, or product titles), you may want the program to ...

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 in ...

Discover More

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

Functioning Check Boxes in a Protected Worksheet

Want to protect a worksheet but maintain the ability to make changes to the check boxes you add to the worksheet? Here is ...

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

2016-12-10 10:48:52

bahadurvijay@hotmail.com

After applying the above code if the data is required to be changed/amended by me what do I do?


2016-01-12 08:10:08

Stevie D

I've already found a way to unlock *blank* cells, but what I'm also wanting to unlock are cells where a formula results in a blank value ... is there a way to do that as well?


2015-07-08 09:50:50

mukesh

i want non blank cell lock after data save and bank cell not protect


2013-10-21 09:30:03

Bryan

If you don't needlessly select cells, the code can be reduced to 3 lines (4, if you wrap the ActiveSheet.Protect line the same way you did):

Sub UnlockEmptyCells()
Cells.Locked = True
Selection.SpecialCells(xlCellTypeBlanks).Locked = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub


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.