WinteE
Well-known Member
- Joined
- Apr 8, 2007
- Messages
- 605
Hi,
I have the following code that should do the following :
When a value is entered in the column 'Stock' that is greater then zero it should unlock the four cells right of the target cell. This part does what it should do.
Otherwise, when the value is less or equal to zero then it should clear the contents of the target cell and of all four cells right from it, and also lock those cells at the right.
I am getting a 'Runtime error 1004' message with "Unable toe set the Locked property of the Range class" when I enter a value less or equal to zero.
I have the following code that should do the following :
When a value is entered in the column 'Stock' that is greater then zero it should unlock the four cells right of the target cell. This part does what it should do.
Otherwise, when the value is less or equal to zero then it should clear the contents of the target cell and of all four cells right from it, and also lock those cells at the right.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = 0
ActiveSheet.Unprotect
If Not Intersect(Target, Range("Stock")) Is Nothing Then
If Target.Value > 0 Then
For i = 1 To 4
With Target.Offset(0, i)
.Locked = False
End With
Next i
Else
For i = 1 To 4
With Target.Offset(0, i)
.ClearContents
.Locked = True
End With
Next i
End If
End If
ActiveSheet.Protect
End Sub
I am getting a 'Runtime error 1004' message with "Unable toe set the Locked property of the Range class" when I enter a value less or equal to zero.