LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select locked/unlocked cells Training Goddess Excel Programming 2 September 22nd 08 09:50 AM
how do you "select locked cells" w/o "select unlocked cells"? princejohnpaulfin Excel Discussion (Misc queries) 3 July 16th 05 03:53 AM
How select unlocked cells only Metallo[_2_] Excel Programming 3 June 11th 04 06:36 AM
Password Protection - Select Unlocked Cells Only Tenk Excel Programming 1 May 18th 04 12:19 PM
Select all the unlocked cells on a worksheet Steven Revell Excel Programming 2 November 11th 03 12:30 PM


All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"