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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,144,275
Messages
5,723,448
Members
422,497
Latest member
dougy99

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