Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Coloring Locked Cells in Microsoft Excel


View products that this article applies to.

Overview

In Excel, we know that there are several layers of protection and the lowest point is by locking cells. By default, all of cells in a workbook is in locked mode. You can set any cell that is locked. For Example, if you want to protect the cells that contain formula, first you have to unlock all cells then selecting the cell that contain formula and lock it. When you have completed, you cannot see the difference between both of them in Microsoft Excel window. So how can we see the difference?

↑ Back to the top


Resolution

To find out which cells are locked, we should give a mark. To do that we have to create a VBA Macro and in this case I will give a red color mark.

↑ Back to the top


What to do

Here the steps to create the coloring locked cells Macro:

  1. Open Microsoft Excel then press [Alt+F11] to show Visual Basic Editor window.
  2. In [Insert] menu, select [Module] to create a module. Then write the following script:
    Sub ColLockCell()
    Dim cll As Object
    For Each cll In Selection
        If cll.Locked = True Then
        cll.Interior.ColorIndex = 9
    End If
    Next cll
    If Selection.Locked = False Then
    MsgBox "There is no locked cell in range that you choose", vbOKOnly, "Locked Cell Checker"
    End If
    End Sub
              


  3. Close VBE window and back to Excel.

↑ Back to the top


How it works

To know how this macro works, please note the following example:

Create locked cell checker

  1. On [Insert] tab Illustrations category, select [Shapes] and create one of them.
    Add text "Locked Cell Checker" then right click on it and select [Assign Macro].
  2. On Assign Macro dialog box, choose [ColLockCell] macro then click [OK].


Test the macro

  1. Select all cells in one worksheet by pressing [Ctrl+A].
  2. On Home tab Cells category, disable the [Locked Cell]toggle button. With this steps, all cells are unlocked.
  3. Now select cells from B2 to D9 then on the Home tab Cells category, enable the [Locked Cell] toggle button.
  4. Select cells from A1 to E10 then click [Locked Cell Checker]button. Cells from B1 to D9 will colored red.


  5. Then select unlocked cells, from example from F1 to H10 then click [Locked Cell Checker] button.
    The Locked Cell Checker message box will displayed.



↑ Back to the top


Community Solutions Content Disclaimer

MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

↑ Back to the top


Keywords: KB2829791, kbcommunity, kbmvp, kbstepbystep

↑ Back to the top

Article Info
Article ID : 2829791
Revision : 7
Created on : 9/25/2013
Published on : 9/25/2013
Exists online : False
Views : 406