Userform to find item price and description based on text box value

RJSIGKITS

Board Regular
Joined
Apr 15, 2013
Messages
109
Hi Guys - I think this one will be a really simple one for you that know, but I'm stuck!

So, I have a user form in which the user enters a product code into a textbox (TextBox1)
They hit the CommandButton to get a description and a price for that item.

I currently have this:

Code:
Private Sub CommandButton1_Click()Description = Application.WorksheetFunction.VLookup(TextBox1.Text, AllProds, 2, 0)
Price = Application.WorksheetFunction.VLookup(TextBox1.Text, AllProds, 8, 0)
End Sub

"Description" and "Price" are named Label fields, which should show the relevant results.
"Allprods" is the sheet name that has all the products on, which has approximately 30,000 products, and this data has also been saved as a TableArray, also called "AllProds".
Column 1 is the column that has the product codes in.
Column 2 is the column that has the Descriptions in.
Column 8 is the column that has the prices in.

This also needs to display a message if there are no items found for the code entered.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Does this work for you?
Code:
Private Sub CommandButton1_Click()
    On Error GoTo errhandler:
    Description = Application.WorksheetFunction.VLookup(TextBox1.Text, Range("AllProds"), 2, 0)
    Price = Application.WorksheetFunction.VLookup(TextBox1.Text, Range("AllProds"), 8, 0)
errhandler:
    MsgBox "No items found matching this description"
End Sub

I assumed AllProds is a range name in the worksheet, if yes, then the above should work, if NO, you don't need the "Range" preceding it
 
Upvote 0
This any good?

Code:
On Error resume next
Description = Application.WorksheetFunction.VLookup(TextBox1.Text, AllProds, 2, 0)
Price = Application.WorksheetFunction.VLookup(TextBox1.Text, AllProds, 8, 0)
On Error Goto 0

If Not IsError(Description) then
DescriptionLabel.Caption=Description
Else
DescriptionLabel.Caption="Error"
End if

If Not IsError(Price) then
PriceLabel.Caption=Price
Else
PriceLabel.Caption="Error"
End if
 
Last edited:
Upvote 0
Does this work for you?
Code:
Private Sub CommandButton1_Click()
    On Error GoTo errhandler:
    Description = Application.WorksheetFunction.VLookup(TextBox1.Text, Range("AllProds"), 2, 0)
    Price = Application.WorksheetFunction.VLookup(TextBox1.Text, Range("AllProds"), 8, 0)
errhandler:
    MsgBox "No items found matching this description"
End Sub

I assumed AllProds is a range name in the worksheet, if yes, then the above should work, if NO, you don't need the "Range" preceding it

Hey, Thank you, that's nearly there.
Currently, it throws up the error message even if it does find the results, though.
Also, is there a way to make the "Price" Label round up its value - currently returns a price of 69.999999997 for example, and I would need this to be 70.00

Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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