ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code to protect cells Outside a given range (https://www.excelbanter.com/excel-programming/442082-vba-code-protect-cells-outside-given-range.html)

omer

VBA code to protect cells Outside a given range
 
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



Bernie Deitrick

VBA code to protect cells Outside a given range
 
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" wrote in message
...
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





omer

VBA code to protect cells Outside a given range
 
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" wrote in message
...
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




.



All times are GMT +1. The time now is 08:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com