Macro to display locked cells?

9tanstaafl9

Well-known Member
Joined
Mar 23, 2008
Messages
535
Does anyone have a macro already written (or know where I could find one) that would somehow indicate which cells on a spreadsheet are locked? Or can that be done with conditional formatting? I would think there is probably an easy way to do this, but I can't find it.

It's okay if it overwrites any background coloring already there, I could check on a copy.

Thanks!
Jennifer
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Code:
Sub SelectUnlockedCells()
    On Error Resume Next
       ActiveWorkbook.Activate
          If Err <> 0 Then
            MsgBox "There are no open workbooks"
          Else
          End If
    Dim WorkRange As Range
    Dim FoundCells As Range
    Dim Cell As Range
    Set WorkRange = ActiveSheet.UsedRange
    For Each Cell In WorkRange
        If Cell.Locked = False Then
            If FoundCells Is Nothing Then
                Set FoundCells = Cell
            Else
                Set FoundCells = Union(FoundCells, Cell)
            End If
        End If
    Next Cell
    If FoundCells Is Nothing Then
        MsgBox "All cells are locked."

    Else
        FoundCells.Select
    End If
End Sub

To select unlocked cells...or:

Code:
Sub SelectLockedCells()
    On Error Resume Next
       ActiveWorkbook.Activate
          If Err <> 0 Then
            MsgBox "There are no open workbooks"
          Else
          End If
    Dim WorkRange As Range
    Dim FoundCells As Range
    Dim Cell As Range
    Set WorkRange = ActiveSheet.UsedRange
    For Each Cell In WorkRange
        If Cell.Locked = True Then
            If FoundCells Is Nothing Then
                Set FoundCells = Cell
            Else
                Set FoundCells = Union(FoundCells, Cell)
            End If
        End If
    Next Cell
    If FoundCells Is Nothing Then
        MsgBox "All cells are unlocked."

    Else
        FoundCells.Select
    End If
End Sub

to select all locked cells.

This is only selecting, not filling the interior of the cell. I'm sure with a little change it can though :).
 
Upvote 0
Just use conditional formatting. You can tell if a cell is locked using the CELL function.

Conditional Formatting Formula:

=CELL("Protect",A1)=1

HTH,
Colin
 
Upvote 0
Excel defaults that all cells are locked it just has no effect until the sheet is protected, so I think you may be asking about a protected sheet? So if the cell is locked no conditional formatting can be done.
 
Upvote 0
Thank you everyone! I appreciate your help. You've just saved me a lot of work, I only feel foolish that I wasted so much time before I asked for advice, or even considered that there was a better way than checking manually.

I wonder if there's a post anywhere of the top things people waste time doing in Excel manually that they would be better off doing with code or shortcut keys...

Thanks again,
Jennifer
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top