Vlookup for Userform, Run-Time error

howitusedtowas

New Member
Joined
Jul 21, 2014
Messages
40
Hi!

I made a userform via ActiveX Controls on my sheet, and I have a list box that uses Vlookup to fill in two other text boxes on my userform. Therefore, when the user clicks the part number from the listbox, the Part description ( TextBox1 ) and Std. Hours (TextBox2) for the part is filled out.

However, I have two different sheets, Vlookup uses, for each Text Box. Meaning,

TextBox1.Value = WorksheetFunction.VLookup(ListBox1.Value, Worksheets("Parts Master").Range("A:B"), 2, False)


TextBox2.Value = WorksheetFunction.VLookup(ListBox1.Value, Worksheets("Lab Master").Range("A:B"), 2, False)

Part description uses the parts master sheet to look up the, and my Std. Hours looks up the Lab Master.


SO HERES MY PROBLEM

Sometimes when the user clicks the part from the listbox, the part description is there but the STD hours isn't listed on my Lab Master. But thats ok, however my excel keeps giving me a Run-Time error. I just want a msg box saying "No STD. Hours found".

I hope that makes sense, I'm pretty new to this!


PLEASE HELP :(:(:(
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Does this work for you?

Code:
Dim x As Variant
x = Application.VLookup(ListBox1.Value, Worksheets("Lab Master").Range("A:B"), 2, False)
If IsError(x) Then
    TextBox2.Value = "No STD. Hours found"
Else
    TextBox2.Value = x
End If
 
Upvote 0
Try

Code:
TextBox1.Value = Application.VLookup(ListBox1.Value, Worksheets("Parts Master").Range("A:B"), 2, False)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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