lock cells with values

  • Thread starter Thread starter Alberto Ast
  • Start date Start date
A

Alberto Ast

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?
 
Hi,

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

Locking has no effect until the sheet is protected.

Mike
 
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).Locked = 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(xlCellTypeConstants), _
Range("A1:P30").SpecialCells(xlCellTypeFormulas)).Locked = True
 
Back
Top