siddharth_kale
New Member
- Joined
- Dec 29, 2010
- Messages
- 24
Hello all,
I have requirement wherein each cell should be allowed to edit only once.
This has to be done for a range of cells. For eg. A1:A10, C1:C10.
I have found the below code but it is not working as desired. The second time when you enter in the same column (any other cell) it doesnt seem to allow, which is should not be the case.
Any other cell should be allowed, again only once.
Any help is appreaciate.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myChangeOnceCells As Range
Dim myCell As Range
Dim pwd As String
pwd = "hi"
Set myChangeOnceCells = Me.Range("A1,A3,A6,D7,C3,B4,B6")
If Intersect(Target.Cells, myChangeOnceCells) Is Nothing Then Exit Sub
Me.Unprotect Password:=pwd
For Each myCell In Intersect(Target.Cells, myChangeOnceCells).Cells
myCell.Locked = True
Next myCell
Me.Protect Password:=pwd
End Sub
I have requirement wherein each cell should be allowed to edit only once.
This has to be done for a range of cells. For eg. A1:A10, C1:C10.
I have found the below code but it is not working as desired. The second time when you enter in the same column (any other cell) it doesnt seem to allow, which is should not be the case.
Any other cell should be allowed, again only once.
Any help is appreaciate.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myChangeOnceCells As Range
Dim myCell As Range
Dim pwd As String
pwd = "hi"
Set myChangeOnceCells = Me.Range("A1,A3,A6,D7,C3,B4,B6")
If Intersect(Target.Cells, myChangeOnceCells) Is Nothing Then Exit Sub
Me.Unprotect Password:=pwd
For Each myCell In Intersect(Target.Cells, myChangeOnceCells).Cells
myCell.Locked = True
Next myCell
Me.Protect Password:=pwd
End Sub