PDA

View Full Version : [SOLVED] VBA to lock specific rows when a worksheet opens



simora
10-10-2014, 09:25 PM
I'm trying to lock specific rows when a worksheet opens.
This is the code that I have which is NOT working.
Its selecting the rows, but, thats it.

What am I doing wrong?



Worksheets(MySht).Activate
Rows(3).Select
Selection.Locked = True
Selection.FormulaHidden = False

Rows(8).Select
Selection.Locked = True
Selection.FormulaHidden = False

Bob Phillips
10-11-2014, 03:28 PM
With Worksheets(MySht)

With .Rows(3)

.Locked = True
.FormulaHidden = False
End With

With .Rows(8)

.Locked = True
.FormulaHidden = False
End With

.Protect
End With

Aussiebear
10-11-2014, 09:55 PM
Could you shorten this a bit more?


With Worksheets(MySht)
With .Rows(3:3,8:8)
.Locked = True
.FormulaHidden = False
.Protect
End With
End With
End Sub

simora
10-13-2014, 07:02 PM
Solutions worked great.

Thanks