Opulence12
New Member
Hi All,
I am very new to VBA and I am trying to figure out the VBA code in excel but i encountered the error code(Run-time error 1004: Unable to set Locked property of Range class) after I protected the sheet after inserting the code:
When i pressed debug, the error highlighted was this: Range("J106:K106").Locked = True
However, they are not merged cells so I do not know what I did wrong. These 2 cells (J106:K106) are 2 separate cells with drop-down lists using data validation. However, if G106 shows the value "N.A.", the cells (J106:K106) are to be locked and prevented from entering the value.
I actually intended to use this VBA code from cells G100 to G106 to link to J100 to K106 respectively.
Please help!
I am very new to VBA and I am trying to figure out the VBA code in excel but i encountered the error code(Run-time error 1004: Unable to set Locked property of Range class) after I protected the sheet after inserting the code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("G106").Value = "N.A." Then
Range("J106:K106").Locked = True
Else
Range("J106:K106").Locked = False
End If
End Sub
When i pressed debug, the error highlighted was this: Range("J106:K106").Locked = True
However, they are not merged cells so I do not know what I did wrong. These 2 cells (J106:K106) are 2 separate cells with drop-down lists using data validation. However, if G106 shows the value "N.A.", the cells (J106:K106) are to be locked and prevented from entering the value.
I actually intended to use this VBA code from cells G100 to G106 to link to J100 to K106 respectively.
Please help!
Last edited by a moderator: