Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Vlookup Error

Status
Not open for further replies.

rjm65

Technical User
May 27, 2003
86
US
I found the following in Excel VBA Programming for Dummies.

Sub GetPrice()
Dim PartNum As Variant
Dim Price As Double
PartNum = InputBox("Enter the Part Number")
Sheets("Prices").Activate
Price = WorksheetFunction. _
VLookup(PartNum, Range("PriceList"), 2, False)
MsgBox PartNum & " costs " & Price
End Sub

I enter a part number and it gives me the corresponding price. If the part number I enter is a perfect match, I get the correct price. If I enter an incorrect part number, I get an error: Run-time error '1004': Unable to get the Vlookup property of the Worksheet Function Class. If I hit debug, the following is highlighted:
Price = WorksheetFunction. _
VLookup(PartNum, Range("PriceList"), 2, False)

I realize I have to use the "FALSE" command because it must find an exact part name to reference with the price. Also, if I hit cancel, it will give me the same error as if I entered an incorrect part number.

Is there any way around this? Ideally I would like no error message if the cancel button is selected, and if an incorrect part number is entered it would be great if a "wrong part number entered" message could be given instead of the Runtime Error-Help-Debug error window. Thanks in Advance. Raymond
 
What about the On Error Resume Next instruction ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That was probably a really basic question, but I'm just starting to learn my way around. Thank you for pointing me in the right direction. I read up a little on the On Error Resume Next instruction and figured out how to use it to fix my problem. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top