Selecting only locked cells

  • Thread starter Thread starter Tim Marsden
  • Start date Start date
T

Tim Marsden

Hi

I want to be able to set a range variable equal to the cells in a Worksheet
which are locked. I will be using visual basic code.

I have looked at xlspecialcells but with no luck.

Tim
 
Might be another way but:

Dim rng As Range
Set rng = ActiveSheet.UsedRange

Dim rngLockedCells As Range
Dim cell As Range
For Each cell In rng
If cell.Locked = True Then
If rngLockedCells Is Nothing Then
Set rngLockedCells = cell
Else
Set rngLockedCells = Union(rngLockedCells,
cell)
End If
End If
Next
rngLockedCells.Select

HTH.

-Brad
 
Hi Tim,

Thanks for participating in the community!

From my understanding to this issue, you are going to obtain one range
object which points to these locked cells in your workbook.

So far as I know, the method from Brad is the solution in this scenario.
From Excel object, there is no one method for us to pick up these locked
cells directly.

If you have any further question regarding this, please feel free to let me
know. Enjoy a nice weekend!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top