VBA code to protect cells Outside a given range

  • Thread starter Thread starter OMER
  • Start date Start date
O

OMER

hi there,
I need to write code allow the user to enter dato only on cells that are
unprotected. What I need is to protect cells outside a given range.
On a 6 x 6 matrix, where N=3, protect all cells on rows and columns 4,5,6
4,5. If N=2, protect all cells in rows and columns 3,4,5,6.

thank you in advance.
NeedHelp
 
I have assumed that your 6x6 range is named Matrix.....

Sub UnprotectMatrix()
Dim N As Integer
N = 3
With Range("Matrix")
.Parent.Unprotect
.Cells.Locked = True
.Columns(1).Resize(, N).Locked = False
.Parent.Protect
End With
End Sub

HTH,
Bernie
MS Excel MVP
 
Thank You very much Bernie.
I made a slight change to it, since I needed to also protect rows 4,5,6.
This is how it ended up.

Sub UnprotectMatrix()
Dim N As Integer
N = 3
With Range("Matrix")
.Parent.Unprotect
.Cells.Locked = True
.Resize(N, N).Locked = False
.Parent.Protect
End With
End Sub

Again, thanks
 
Back
Top