ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting only locked cells (https://www.excelbanter.com/excel-programming/292662-selecting-only-locked-cells.html)

Tim Marsden

Selecting only locked cells
 
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







brad

Selecting only locked cells
 
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
-----Original Message-----
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






.


Wei-Dong Xu [MSFT]

Selecting only locked cells
 
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.



All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com