lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I want to improve the code below so if a user entered a wrong name, then vba will give error message. I tried with IfError() as below but got error message. Thank you so much.
<tbody>
</tbody>
I want to improve the code below so if a user entered a wrong name, then vba will give error message. I tried with IfError() as below but got error message. Thank you so much.
Code:
Sub mylookup()
Dim xname As String
Dim xnumber As Integer
xname = InputBox("name")
xnumber = Application.WorksheetFunction.VLookup(xname, Range("a1:b100"), 2, False)
'xnumber = Application.WorksheetFunction.IfError(Application.WorksheetFunction.VLookup(xname, Range("a1:b100"), 2, False), MsgBox("not good name"))
MsgBox xnumber
End Sub
name | ph# |
mary1 | 1 |
mary2 | 2 |
john3 | 3 |
<tbody>
</tbody>