Application.Match

henrik_ros

New Member
Joined
Jun 20, 2019
Messages
7
Hello

I am pretty new to VBA and I have a question

In column A i have thousands of IDs, in column B their prices

I have a userform where the user enters ID in textbox1 and in textbox2 the prices is retrieved.

My question is if there is possible to enter multiple IDs in textbox1 and have those IDs added together in textbox2?
If the user enters IDs like ID1,ID2,ID3 in textbox1 - in textbox2 it would sum the prices together.

Below is the code, that works for 1 ID


Private Sub TextBox1_Change()


Dim Res As Variant

Res = Application.Match(TextBox1.Value, Worksheets("Blad2").Range("A1:A100"), 0)


If Not IsError(Res) Then
TextBox2.Value = Worksheets("Blad2").Range("B" & Res).Value
Else
TextBox2.Value = "Price is missing"
End If
End Sub



Best regards Henrik
 
Also with the provided code you do not use spaces between the commas ie ID1,ID2,ID3. Do not do this: ID1, ID2, ID3
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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