How merge amounts into textbox based on two comboboxes instead of one combobox

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
146
Office Version
  1. 2019
Platform
  1. Windows
Hello
my data as in picture
BR.xlsm
ABCDE
1ITEMDATECUSTOMERIDQTY
2101/01/2024mkl1SDFR1000200
3201/01/2024mkl1SDFR1000300
4301/01/2024mkl1SDFR1000100
5401/01/2024mkl1SDFR1001200
6TOTAL01/01/2024110
7102/01/2024malkSDFR1000200
8202/01/2024malkSDFR1002300
9TOTAL02/01/2024110
ORDERS

I want merging QTY into textbox1 based on column C,D after matching combobox1,2 with columns C,D like this
DE.JPG

current code will merge based on combobox1 is matched with column D
VBA Code:
Private Sub CommandButton1_Click()
 Dim ws As Worksheet, LR As Long, qtyP As Double, qtyT As Double
  If ComboBox1.Value <> "" Then
   Set ws = Sheets("ORDERS")
    LR = ws.Cells(Rows.Count, 3).End(3).Row
    qtyP = WorksheetFunction.SumIf(ws.Range("D2:D" & LR), ComboBox1.Value, ws.Range("E2:E" & LR))
   
   qtyT = qtyT + qtyP
   TextBox1.Text = qtyT
  End If
End Sub
I hope somebody can adapt with my requirements.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try using Sumifs, maybe like this:
VBA Code:
qtyP = WorksheetFunction.SumIfs(ws.Range("E2:E" & LR), ComboBox1.Value, ws.Range("D2:D" & LR), ComboBox2.Value, ws.Range("C2:C" & LR))
Note: in sumifs, the first argument is the sum_range
Here's a good resource about sumifs:
SUMIFS Function
 
Upvote 0
Unfortunately shows error objects require in the line where contains sumifs function!
What's my bad?!
 
Upvote 0
Unfortunately shows error objects require in the line where contains sumifs function!
What's my bad?!
Not sure why.
Could you please upload a sample workbook (without sensitive data) to a file-sharing site like Dropbox.com or Google Drive, and then share the link here? Also, ensure that the link is accessible to anyone.
 
Upvote 0
Sorry, I applied wrong sequence in the function arguments.
Try this:
VBA Code:
Private Sub CommandButton1_Click()
 Dim ws As Worksheet, LR As Long, qtyP As Double, qtyT As Double
  If ComboBox1.Value <> "" Then
   Set ws = Sheets("ORDERS")
    LR = ws.Cells(Rows.Count, 3).End(3).Row
    qtyP = WorksheetFunction.SumIfs(ws.Range("E2:E" & LR), ws.Range("D2:D" & LR), ComboBox1.Value, ws.Range("C2:C" & LR), ComboBox2.Value)

   qtyT = qtyT + qtyP
   TextBox1.Text = qtyT
  End If
End Sub
 
Upvote 0
Solution
excellent ! (y)
can you modify the code,please? if I select the ID from combobox1 without select customer from combobox2 (should merge based on just ID) then should merge as in OP and if I select CUSTOMER from combobox2 then will implement as your solution .
thanks again .
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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