lock cells with values

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?
 
M

Mike H

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
 
R

Rick Rothstein

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top