Select locked/unlocked cells

T

Training Goddess

I came across an excellent procedure here in the Excel Programming discussion
group last week but didn't capture it to disk. Would someone be able to
provide the code to select all locked/unlocked cells on a worksheet?

MUCH appreciated!

Training Goddess
 
P

paul.robinson

Hi Training Goddess (cool name!)
Search this group using

select all locked/unlocked cells

-always search as a first option.
regards
Paul
 
M

Mike H

Maybe

Sub mariner()
Dim MyState As Boolean
Dim MyType As String
Dim MyRange As Range, C As Range
response = InputBox("Select What? Locked (L) or Unlocked (U)")
If response = vbCancel Then Exit Sub
Select Case UCase(response)
Case "L"
MyState = True
MyType = "Unlocked"
Case "U"
MyState = False
MyType = "Locked"
Case Else
Exit Sub
End Select
For Each C In ActiveSheet.UsedRange
If C.Locked = MyState Then
If MyRange Is Nothing Then
Set MyRange = C
Else
Set MyRange = Union(MyRange, C)
End If
End If
Next C
If MyRange Is Nothing Then
MsgBox "All cells are " & MyType
Else
MyRange.Select
End If
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top