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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,215,422
Messages
6,124,811
Members
449,191
Latest member
rscraig11

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