merge QTY on textbox based on selected combobox on userform if the adjacent cell doesn't equal zero

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hi
I want searching the BRAND in in column E for AS sheet based on selected from combobox1 and if doesn't contain zero in column H then merge duplicates BRAND IN column F in textbox1
the sheet
AA Microsoft Excel ‫(3)‬.xlsx
EFGH
1BRANDQTYUNIT PRICETOTAL
2BS 1200R20 G580 JAP50015000
3BS 1200R20 G580 THI30016000
4BS 1200R20 R187 JAP15014500
5BS 1200R24 G580 JAP26020000
6BS 1200R20 G580 JAP3401550527000
7BS 1200R20 G580 THI80014401152000
8BS 315/80R22.5 R184 THI5001250625000
9BS 1200R20 G580 JAP3001600480000
10BS 1200R20 G580 THI2501700425000
AS
Cell Formulas
RangeFormula
H6:H10H6=IF(AND(IN!$C$7=C6,ISNUMBER(MATCH($E6,IN!$C$3:$C$300,0))),0,F6*G6)

so when select ID from column E then will merge QTY F in textbox1 if the ID doesn't contain zero in adjacent cell for column H
ss1.JPG



I have this code to populate the QTY in textbox1 without merge duplicates ID .
VBA Code:
Private Sub ComboBox1_Change()
Dim c As Range
    Dim ws As Worksheet
    Set ws = Sheets("AS")
With ws
   
    Set c = .Range("E:E").Find(What:=ComboBox1.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not c Is Nothing Then
          TextBox1.Value = c.Offset(, 1).Value
          End If
          End With
End Sub
I hope some body help
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this:

VBA Code:
Private Sub ComboBox1_Change()
  Dim i As Long
  Dim tot As Double
  Dim ws As Worksheet
 
  Set ws = Sheets("AS")
  For i = 2 To ws.Range("E" & Rows.Count).End(3).Row
    If ws.Range("E" & i).Value = ComboBox1.Value And _
      ws.Range("H" & i).Value <> 0 Then
      tot = tot + ws.Range("F" & i).Value
    End If
  Next
  TextBox1.Value = tot
End Sub

If there are many records, try the following:
VBA Code:
Private Sub ComboBox1_Change()
  Dim r As Range, f As Range, cell As String
  Dim tot As Double
  Dim ws As Worksheet
  
  Set ws = Sheets("AS")
  Set r = ws.Range("E2", ws.Range("E" & Rows.Count).End(3))
  Set f = r.Find(ComboBox1.Value, , xlValues, xlWhole)
  If Not f Is Nothing Then
    cell = f.Address
    Do
      If ws.Range("H" & f.Row).Value <> 0 Then
        tot = tot + ws.Range("F" & f.Row).Value
      End If
      Set f = r.FindNext(f)
    Loop While f.Address <> cell
  End If
  
  TextBox1.Value = tot
End Sub
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

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