Selecting/highlighting only unprotected cells?

serickson

Board Regular
Joined
Mar 17, 2002
Messages
61
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.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top