Selecting/highlighting only unprotected cells? :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Selecting/highlighting only unprotected cells?
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

serickson
Board Regular


Joined: 18 Mar 2002
Posts: 17
Location: Denver, Colorado

Status: Offline

 Reply with quote  

Selecting/highlighting only unprotected cells?

I have a large worksheet that I will publish to a group. I have multiple sheets where certain cells are protected. In testing, is there a way to automatically select all unprotected cells or to highlight them. I know that I can tab through the page and excel will only stop on unprotected cells, but the sheets are too big for this approach.

As always, your ideas are appreciated.

Post Wed Oct 15, 2003 3:41 pm 
 View user's profile Send private message Send e-mail

DRJ
Board Master
Board  Master


Joined: 18 Feb 2002
Posts: 1022
Location: California
Flag: Usa

Status: Offline

 Reply with quote  

Re: Selecting/highlighting only unprotected cells?

Something like this??

Sub test()

Dim NewSelection As String
Dim Cell As Object

For Each Cell In Selection
If Range(Cell.Address).Locked = true Then
Else
NewSelection = NewSelection & "," & Cell.Address
End If
Next

NewSelection = Mid(NewSelection, 3, Len(NewSelection))

Range(NewSelection).Select

End Sub

Hope this helps

Jacob

Post Wed Oct 15, 2003 4:03 pm 
 View user's profile Send private message Send e-mail

serickson
Board Regular


Joined: 18 Mar 2002
Posts: 17
Location: Denver, Colorado

Status: Offline

 Reply with quote  

Re: Selecting/highlighting only unprotected cells?

That sir, is wonderful.

(now what do I do with it?)

Post Wed Oct 15, 2003 4:06 pm 
 View user's profile Send private message Send e-mail

Damon Ostrander
MrExcel MVP


Joined: 18 Feb 2002
Posts: 1527
Location: Denver, Colorado USA
Flag: Usa

Status: Offline

 Reply with quote  

Re: Selecting/highlighting only unprotected cells?

Hi serickson,

Here is another slightly different approach. This macro selects all the unlocked cells on the active worksheet WITHIN THE USED RANGE. The used range is the smallest rectangular range of cells that contain data. This definition is important because it is possible if the worksheet doesn't have any filled cells around the unlocked cells that the cells will not be within the used range and therefore not be highlighted.

To use this macro, first insert it into a macro module by going to the VBE (keyboard Alt-TMV), insert a new macro module (Alt-IM), and paste the code into the code pane. To run the macro use Alt-TMM or assign it to a button or keyboard shortcut.


Sub SelectUnlocked()
'Selects all unlocked cells within used range on the active worksheet
Dim Cell As Range
Dim UnlockedCells As Range
Dim CellCount As Long
CellCount = 0
For Each Cell In ActiveSheet.UsedRange
If Not Cell.Locked Then
If CellCount = 0 Then
Set UnlockedCells = Cell
Else
Set UnlockedCells = Union(UnlockedCells, Cell)
End If
CellCount = CellCount + 1
End If
Next Cell
UnlockedCells.Select
'Comment this out if you don't want to see the count:
MsgBox CellCount & " unlocked cells", vbInformation, "Select Unlocked Cells"
End Sub
_________________
Keep Excelling.

Damon

Post Wed Oct 15, 2003 4:24 pm 
 View user's profile Send private message Send e-mail Visit poster's website

DRJ
Board Master
Board  Master


Joined: 18 Feb 2002
Posts: 1022
Location: California
Flag: Usa

Status: Offline

 Reply with quote  

Re: Selecting/highlighting only unprotected cells?

When do you want it to activate

You can put it in the sheet_activate module in vba

Just add range(MyRange).select to the top of the code. Replace MyRange with your range that you use. The code will then run whenever the sheet is activated.

Post Wed Oct 15, 2003 4:33 pm 
 View user's profile Send private message Send e-mail
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.