ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   lock cells with values (https://www.excelbanter.com/excel-programming/435113-lock-cells-values.html)

Alberto Ast[_2_]

lock cells with values
 
with below statements

Range("A1:P30").Select
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Locked = True

I can select a range and then lock any cell with formulas...

How do I do same but want to lock any cell with formulas and/or values?

Mike H

lock cells with values
 
Hi,

Dim MyRange As Range
Set MyRange = Range("A1:P30").SpecialCells(xlCellTypeConstants)
Range("A1:P30").SpecialCells(xlCellTypeFormulas).S elect
Set MyRange = Union(MyRange, Selection)
MyRange.Locked = True

Locking has no effect until the sheet is protected.

Mike

"Alberto Ast" wrote:

with below statements

Range("A1:P30").Select
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Locked = True

I can select a range and then lock any cell with formulas...

How do I do same but want to lock any cell with formulas and/or values?


Rick Rothstein

lock cells with values
 
with below statements

Range("A1:P30").Select
Selection.SpecialCells(xlCellTypeFormulas, 23).Select
Selection.Locked = True

I can select a range and then lock any cell with formulas...


On Error Resume Next
Range("A1:P30").SpecialCells(xlCellTypeFormulas).L ocked = True

How do I do same but want to lock any cell with formulas and/or values?


On Error Resume Next
Union(Range("A1:P30").SpecialCells(xlCellTypeConst ants), _
Range("A1:P30").SpecialCells(xlCellTypeFormulas)). Locked = True

--
Rick (MVP - Excel)




All times are GMT +1. The time now is 10:16 PM.

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