How to select all unlocked cells on a sheet?
I meant to replace this portion of the text:
"Or you can use the .findformat." with the "it would be nice to ..." portion,
but messed up.
Dave Peterson wrote:
You can either loop through each cell and create a range.
Or you can use the .findformat. It would be nice to use the .findnext method,
but that doesn't work with formatting (at least not in xl2003).
Option Explicit
Sub testme()
Dim wks As Worksheet
Dim myUnlockedRng As Range
Dim FoundCell As Range
Dim FirstAddress As String
Set wks = ActiveSheet
With wks
'clear any existing formatting that was used
Application.FindFormat.Clear
'just the unlocked cells
Application.FindFormat.Locked = False
Set FoundCell = .Cells.Find(what:="", _
after:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False, _
searchformat:=True)
If FoundCell Is Nothing Then
'not one unlocked cell!
Else
'keep track of where the first one was, so we can quit
'when we find this again.
FirstAddress = FoundCell.Address
'start building the range of unlocked cells
Set myUnlockedRng = FoundCell
Do
Set FoundCell = .Cells.Find(what:="", _
after:=FoundCell, _
LookIn:=xlFormulas, _
lookat:=xlPart, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False, _
searchformat:=True)
If FoundCell Is Nothing Then
Exit Do
End If
If FoundCell.Address = FirstAddress Then
Exit Do
End If
'add to the growing range
Set myUnlockedRng = Union(myUnlockedRng, FoundCell)
Loop
End If
End With
If myUnlockedRng Is Nothing Then
MsgBox "None found!"
Else
Application.Goto myUnlockedRng ', scroll:=True
End If
End Sub
Ted M H wrote:
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?
--
Dave Peterson
--
Dave Peterson
|