Vlookups Vba

brettvba

MrExcel MVP
Joined
Feb 18, 2002
Messages
1,030
Hi Ppl,

I have written the following code to provide a vlookup function for my textbox this works great.

Problem is if the vlookup can't find the value is assigns the value of Desc to be Error 2042 which when used comes out as #N/A.

Question is how can I pick up that error and direct my actions accordingly?

With Sheets("Sheet1")
Desc = Application.VLookup(CDbl(ProdCode), Range("A:D"), 3, False)
End With

Any Help is appreciated

Rgds Brett
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
L

Legacy 98055

Guest
Hi Brett.
Place this below your lookup code to test the type returned.<pre>
Debug.Print TypeName(Desc)
If TypeName(Desc) = "Error" Then
'solve problem
End If</pre>
Tom

By the way, I'm assuming that Desc is a variant. This may or may not matter.
This message was edited by TsTom on 2002-10-13 21:23
 

Forum statistics

Threads
1,181,645
Messages
5,931,200
Members
436,782
Latest member
talhafiaz

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
Top