Hi all,
I have a worksheet with a range of cells containing names (F4:H5) and upon clicking the cell from the range, the cell value(name) gets copied and pasted to B4:B9.
Then the adjacent columns (C4:C9 and D4:D9) do vlookup to look up the age and score from the reference range (F15:H20).
Lastly, I have a clear button(B20) which clears B4:B9 on click.
The problem I'm having is, I need the range C4:D9 and F15:H20 to be locked, but when I try to do so, the VBA stops working properly.
I've tried to lock the worksheet with all the cell unprotected but doesn't seem to work either way.
Any inputs on how to fix this would be much appreciated.
Below is the link to the worksheet and the code I used.
Thanks!
I have a worksheet with a range of cells containing names (F4:H5) and upon clicking the cell from the range, the cell value(name) gets copied and pasted to B4:B9.
Then the adjacent columns (C4:C9 and D4:D9) do vlookup to look up the age and score from the reference range (F15:H20).
Lastly, I have a clear button(B20) which clears B4:B9 on click.
The problem I'm having is, I need the range C4:D9 and F15:H20 to be locked, but when I try to do so, the VBA stops working properly.
I've tried to lock the worksheet with all the cell unprotected but doesn't seem to work either way.
Any inputs on how to fix this would be much appreciated.
Below is the link to the worksheet and the code I used.
Thanks!
Test.zip
drive.google.com
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("F4:H5")) Is Nothing Then
On Error GoTo Oops
Target.Copy Range("B4:B9").SpecialCells(xlBlanks)(1)
On Error GoTo 0
ElseIf Target.Address(0, 0) = "B20" Then
Range("B4:B9").ClearContents
End If
Exit Sub
Oops:
MsgBox "No space available"
End Sub