VlookUp error

Whistler

Board Regular
Joined
Jul 14, 2011
Messages
61
HI I'm trying to add function to my input form that when user puts ID number in to IDBox, the name come up automaticly in to NameBox.

aTable is my Table where I have ID in first column and name in second.

Code:
Private Sub IDBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim ws As Worksheet
Set ws = Worksheets("NamesBase")
Dim aTable As Range
Dim IDBoxValue As String
Dim NameFromID As String
IDBoxValue = IDBox.Value
Set aTable = ws.Range("A:B")

NameFromID = Application.WorksheetFunction.VLookup(IDBoxValue, aTable, 2, False)
NameBox.Value = NameFromID
End Sub

I'm getting "Unable to get the Vlookup property of the WorksheetFunction class" error


Thanks for your help.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
That means that it isn't finding a match.

Are the values in column A strings or numbers?
 
Upvote 0
Hi

What are your ID values in the first column? Are they numbers? This might explain why you get no match even when you think there should be one. You need to ensure IDBoxValue is also a number in which case (and not a string).
 
Upvote 0
Hi, Thanks for the answer. The column A is a type General, but there are numbers like 54180. Thanks
 
Upvote 0
Try

Rich (BB code):
Private Sub IDBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim ws As Worksheet
Set ws = Worksheets("NamesBase")
Dim aTable As Range
Dim IDBoxValue As Variant
Dim NameFromID As String
IDBoxValue = Val(IDBox.Value)
Set aTable = ws.Range("A:B")

NameFromID = Application.VLookup(IDBoxValue, aTable, 2, False)
NameBox.Value = NameFromID
End Sub
 
Upvote 0
Are the values in column A only composed of digits (0-9) and nothing else? If so, then you can amend your code to the below:

Code:
Private Sub IDBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim ws As Worksheet
Set ws = Worksheets("NamesBase")
Dim aTable As Range
Dim IDBoxValue As Long
Dim NameFromID As String
IDBoxValue = Val(IDBox.Value)
Set aTable = ws.Range("A:B")

NameFromID = Application.WorksheetFunction.VLookup(IDBoxValue, aTable, 2, False)
NameBox.Value = NameFromID
End Sub

If, however, they are a mixture of alphanumeric characters, then I think it might be best to convert all the values in column A of your sheet to text values (format the column as Text via Format>Cells>Number tab, and then select the column and go Data>TextToColumns>Delimited>Next>Next and make sure the you choose an import format of Text>Finish). The vlookup should then work.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top