hello
I have userform when run it will shows the data based on sheet and the combobox will search based on column B . what I need it when run the userform should merge duplicates items based on column 2 in listbox and summing th values just for two columns 4,6 (QTY,TOTAL )in listbox and ignore the column(5) PRICE shouldn't show in list box
the same thing when using combobox to search for the item should be merged with the same conditions as when userform shows .
last thing I would show numberformat for the numbers in listbox for columns 4,6 (QTY,TOTAL ) like this #,##0.00.
this my data
userform
I have userform when run it will shows the data based on sheet and the combobox will search based on column B . what I need it when run the userform should merge duplicates items based on column 2 in listbox and summing th values just for two columns 4,6 (QTY,TOTAL )in listbox and ignore the column(5) PRICE shouldn't show in list box
the same thing when using combobox to search for the item should be merged with the same conditions as when userform shows .
last thing I would show numberformat for the numbers in listbox for columns 4,6 (QTY,TOTAL ) like this #,##0.00.
this my data
1.xlsm | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | DATE | CODE | BRAND | QTY | PRICE | TOTAL | ||
2 | 11/21/2020 | CC1 | FOOD1 | 234.00 | 65.00 | 15,210.00 | ||
3 | 5/21/2020 | CC2 | FOOD2 | 56.00 | 78.00 | 4,368.00 | ||
4 | 5/22/2020 | CC3 | FOOD3 | 89.00 | 98.00 | 8,722.00 | ||
5 | 5/23/2020 | CC4 | FOOD4 | 56.00 | 45.00 | 2,520.00 | ||
6 | 5/24/2020 | CC5 | FOOD5 | 76.00 | 34.00 | 2,584.00 | ||
7 | 5/25/2020 | CC6 | FOOD6 | 234.00 | 67.00 | 15,678.00 | ||
8 | 5/26/2020 | CC7 | FOOD7 | 567.00 | 78.00 | 44,226.00 | ||
9 | 5/27/2020 | CC8 | FOOD8 | 875.00 | 54.00 | 47,250.00 | ||
10 | 5/28/2020 | CC9 | FOOD9 | 675.00 | 34.00 | 22,950.00 | ||
11 | 5/29/2020 | CC10 | FOOD10 | 500.00 | 87.00 | 43,500.00 | ||
12 | 5/30/2020 | CC1 | FOOD1 | 789.00 | 65.00 | 51,285.00 | ||
13 | 5/31/2020 | CC2 | FOOD2 | 456.00 | 78.00 | 35,568.00 | ||
14 | 6/1/2020 | CC3 | FOOD3 | 678.00 | 45.00 | 30,510.00 | ||
15 | 6/2/2020 | CC4 | FOOD4 | 456.00 | 67.00 | 30,552.00 | ||
16 | 6/3/2020 | CC5 | FOOD5 | 789.00 | 99.00 | 78,111.00 | ||
17 | 6/4/2020 | CC6 | FOOD6 | 234.00 | 65.00 | 15,210.00 | ||
18 | 6/5/2020 | CC7 | FOOD7 | 789.00 | 54.00 | 42,606.00 | ||
19 | 6/6/2020 | CC8 | FOOD8 | 567.00 | 56.00 | 31,752.00 | ||
20 | 6/7/2020 | CC9 | FOOD9 | 456.00 | 76.00 | 34,656.00 | ||
SHEET1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
F2:F20 | F2 | =D2*E2 |
userform
VBA Code:
Private Sub ComboBox1_Change()
Set ws = Sheets("SHEET1")
Set Rng = ws.Range("A1:F" & ws.Range("A" & ws.Rows.Count).End(xlUp).Row)
MyArray = Rng
On Error Resume Next
lijst = MyArray
arg = 0
For i = 1 To UBound(lijst)
If InStr(1, lijst(i, 2), ComboBox1, vbTextCompare) > 0 Then
arg = arg + 1
End If
Next i
ReDim nwlijst(arg - 1, 6)
arg = 0
For i = 1 To UBound(lijst)
If InStr(1, lijst(i, 2), ComboBox1, vbTextCompare) > 0 Then
For k = 1 To 6
nwlijst(arg, k - 1) = lijst(i, k)
Next k
arg = arg + 1
End If
Next
ListBox1.List = nwlijst
End Sub
Private Sub UserForm_Initialize()
Set ws = Sheets("SHEET1")
Set Rng = ws.Range("A1:F" & ws.Range("A" & ws.Rows.Count).End(xlUp).Row)
With Me.ListBox1
.Clear
.ColumnHeads = False
.ColumnCount = Rng.Columns.Count
MyArray = Rng
.List = MyArray
.ColumnWidths = "150;150;150"
.TopIndex = 0
End With
With ws.Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row)
v = .Value
End With
With CreateObject("scripting.dictionary")
.comparemode = 1
For Each e In v
If Not .exists(e) Then .Add e, Nothing
Next
If .Count Then Me.ComboBox1.List = Application.Transpose(.keys)
End With
End Sub