How to select all unlocked cells on a sheet?
Give the following macro a try. By default, it works on the ActiveSheet, but
you can change this to a specific worksheet by changing the worksheet
reference in the With statement on the third code line.
Sub ClearUnlockedCells()
Dim C As Range, FoundCells As Range, FirstAddress As String
Application.FindFormat.Locked = False
With ActiveSheet.UsedRange
Set C = .Find("", SearchFormat:=True)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
If FoundCells Is Nothing Then
Set FoundCells = C
Else
Set FoundCells = Union(FoundCells, C)
End If
Set C = .Find("", after:=C, SearchFormat:=True)
Loop While Not C Is Nothing And C.Address < FirstAddress
End If
If Not FoundCells Is Nothing Then FoundCells.Select
End With
Application.FindFormat.Clear
End Sub
--
Rick (MVP - Excel)
"Ted M H" wrote in message
...
I need a sub procedure that selects all unlocked cells on a worsheet.
Go to special doesn't offer this as an option. What I want to do is akin
to
something like Selection.SpecialCells(xlCellTypeBlanks).Select, but
instead
of blanks I want to select cells where Locked = False.
I've tried a few things with Application.FindFormat.Locked = False, but I
can't figure out to select ALL the FindFormat.Locked = False cells.
Any suggestions?
|