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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,727
Members
449,049
Latest member
MiguekHeka

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