From: OMER on
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


From: "Bernie Deitrick" deitbe on
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


"OMER" <OMER(a)discussions.microsoft.com> wrote in message
news:9D7B8D6F-7CF5-43B3-A6B2-2ACF50DDAAE0(a)microsoft.com...
> 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
>
>


From: OMER on
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



"Bernie Deitrick" wrote:

> 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
>
>
> "OMER" <OMER(a)discussions.microsoft.com> wrote in message
> news:9D7B8D6F-7CF5-43B3-A6B2-2ACF50DDAAE0(a)microsoft.com...
> > 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
> >
> >
>
>
> .
>
 | 
Pages: 1
Prev: 2 codes in one sheet
Next: Ignore Blank Cells