Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guy,
Active sheet Column A can select name from a dropdown list in worksheets("Data") Column L and can input name. I want to input a name and if it is not found in the dropdown list, then add this (new)name to the last empty cell in Column L.
My code does not work but shows no error. Appreciate any help to make it works.
Active sheet Column A can select name from a dropdown list in worksheets("Data") Column L and can input name. I want to input a name and if it is not found in the dropdown list, then add this (new)name to the last empty cell in Column L.
My code does not work but shows no error. Appreciate any help to make it works.
VBA Code:
Sub AddName2()
Dim srchRng As Range, oRng As Range
Dim M As Range, N As Range
Dim slastRow As Long, olastRow As Long
olastRow = Range("A3").End(xlDown).Row
Set oRng = Range("A3:A" & olastRow)
Set srchRng = Worksheets("Data").Range("L2:L" & slastRow)
On Error GoTo ErrHandler:
If Not Intersect(Target, Range("A3:A" & olastRow)) Is Nothing Then
If Not IsNumeric(Target.Value) Then
Application.EnableEvents = False
For Each N In oRng
Set M = srchRng.Find(Target.Value, , xlValues, xlWhole)
If M = N Then
Else
Target.Value = Worksheets("Data").Range("L2:L" & slastRow + 1).Value
End If
Next N
ErrHandler:
Application.EnableEvents = True
End If
Application.EnableEvents = True
End Sub