VBA code to protect cells Outside a given range

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
 
B

Bernie Deitrick

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
 
O

OMER

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
 

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