I've got a list of names (A1:A4) and one of objects right next to it (B1:B4). Every time the list of names changes I would like Excel to
1) check if the name that was just entered exists within range J1:J4
2) if it does, enter its matching value (K1:K4) in the cell right next to it (so, column B). Else, exit the sub and let the end user enter whatever they want.
When I try to run the code nothing happens. I know I'm triggering the correct cells, that the value does exist in the J1:K4 range and that Excel recognizes "Activecell" as the one that was just edited but I haven't been able to verify much else. Could anyone help me?
1) check if the name that was just entered exists within range J1:J4
2) if it does, enter its matching value (K1:K4) in the cell right next to it (so, column B). Else, exit the sub and let the end user enter whatever they want.
When I try to run the code nothing happens. I know I'm triggering the correct cells, that the value does exist in the J1:K4 range and that Excel recognizes "Activecell" as the one that was just edited but I haven't been able to verify much else. Could anyone help me?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A4")) Is Nothing Then GoTo Line1
Line1:
If Application.WorksheetFunction.CountIf(Range("J1:J4"), ActiveCell.Value) = True Then
ActiveCell.Offset(0, 1) = WorksheetFunction.Index(Sheets("Foglio2").Range("J1:K4"), WorksheetFunction.Match(ActiveCell.Value, Sheets("Foglio2").Range("J1:J4"), 0), 2)
If Not Application.WorksheetFunction.CountIf(Range("J1:J4"), ActiveCell.Value) = True Then
Exit Sub
End If
End If
End Sub