PDA

View Full Version : Protect only selected cells



sasa
03-28-2009, 12:21 AM
Good Morning,
I need to protect only some cells of a column, for example column H, from H16 to H 139 by a macro. Is there a little help.

Thanks

joms
03-28-2009, 02:08 AM
hi sasa, try this:

to unlock go to tools-> Protection->Unprotect sheet


Sub x()

'
' Macro4 Macro
' Macro recorded 3/28/2009 by joms
'

'
Cells.Select
Selection.Locked = False
Selection.FormulaHidden = False
Range("h16:h139").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub

mdmackillop
03-28-2009, 06:48 AM
Tidying up Joms' code to get rid of these inefficient selections

Sub x()
With Cells
.Locked = False
.FormulaHidden = False
With .Range("h16:h139")
.Locked = True
.FormulaHidden = False
End With
End With
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

joms
03-28-2009, 06:08 PM
thanks, mdmackillop... that code was just recorded... at i least i learn something from you... :)