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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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