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
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