abdo meghari
Well-known Member
- Joined
- Aug 3, 2021
- Messages
- 612
- Office Version
- 2019
Hi,
I search for code to populate data on form based on combo box , but my project will be more More expansive
here is what I got it so far wit I try populate items in combobox1 for sheets names and combobox2 for headers should search for it .
here is data in four sheets.
when I select sheet name from combobox1, select the header from combobox2 and write the ID is relating with the header in textbox3 then will populate data in listbox and sum colulmn QTY in textbox4 and sum column TOTAL in textbox5 like this
example SV sheets
when just select header and ID without sheet name will add column sheets names in third column in listbox
as to dates(textbox1,textbox2) should be when select sheet name and header or when just select header without sheet name .
I hope correct my error and improve based on my requirements.
thanks
I search for code to populate data on form based on combo box , but my project will be more More expansive
here is what I got it so far wit I try populate items in combobox1 for sheets names and combobox2 for headers should search for it .
VBA Code:
Option Explicit
Dim a As Variant
Private Sub UserForm_Activate()
Dim ws As Variant
For Each ws In Sheets(Array("SV", "SR", "VS", "RS"))
ComboBox1.AddItem ws.Name
Next ws
Dim arr As Variant
Dim sh As Worksheet
Set sh = Sheets("SV")
For Each arr In Array("CUSTOMER", "INV.NO", "BRAND", "QTY", "PRICE", "TOTAL")
ComboBox2.AddItem arr
Next arr
a = Sheets(ComboBox1).Range("A2:H" & Sheets("ComboBox1").Range("D" & Rows.Count).End(3).Row).Value
End Sub
Private Sub TextBox3_Change()
Call FilterData
End Sub
Sub FilterData()
Dim txt1 As String, txt2 As String, txt3 As String
Dim i As Long, j As Long, k As Long
ListBox1.Clear
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a)
If TextBox3 = "" Then txt1 = a(i, 4) Else txt1 = TextBox3
If LCase(a(i, 4)) Like LCase(txt1) Then
k = k + 1
For j = 1 To 8
b(k, j) = a(i, j)
Next
End If
Next
If k > 0 Then ListBox1.List = b
End Sub
here is data in four sheets.
COL.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | ITEM | DATE | CUSTOMER | INV.NO | BRAND | QTY | PRICE | TOTAL | ||
2 | 1 | 15/06/2023 | CCF-1000 | BSTR_23448 | BS 750R16 R230 JAP | 4.00 | 500.00 | 2,000.00 | ||
3 | 2 | 15/06/2023 | CCF-1000 | BSTR_23448 | BS 700R16 R230 JAP | 2.00 | 400.00 | 800.00 | ||
4 | SUM | 2,800.00 | ||||||||
5 | 1 | 15/09/2023 | CCF-1001 | BSTR_23449 | GO 1200R20 AZ0026 CHI | 1.00 | 920.00 | 920.00 | ||
6 | 2 | 15/09/2023 | CCF-1001 | BSTR_23449 | GO 1200R20 AZ183 CHI | 2.00 | 1,000.00 | 2,000.00 | ||
7 | SUM | 2,920.00 | ||||||||
8 | 1 | 15/09/2023 | CCF-1000 | BSTR_23450 | BS 1200R20 G580 JAP | 10.00 | 1,800.00 | 18,000.00 | ||
9 | 2 | 15/09/2023 | CCF-1000 | BSTR_23450 | BS 1200R20 R187 JAP | 10.00 | 1,800.00 | 18,000.00 | ||
10 | 3 | 15/09/2023 | CCF-1000 | BSTR_23450 | BS 1200R20 G580 THI | 10.00 | 1,800.00 | 18,000.00 | ||
11 | SUM | 54,000.00 | ||||||||
12 | 1 | 16/09/2023 | CCF-1002 | BSTR_23451 | BS 215/60R16 ER30 JAP | 4.00 | 400.00 | 1,600.00 | ||
13 | SUM | 1,600.00 | ||||||||
14 | 1 | 16/09/2023 | CCF-1001 | BSTR_23452 | BS 1200R20 G580 JAP | 5.00 | 1,800.00 | 9,000.00 | ||
15 | SUM | 9,000.00 | ||||||||
16 | 1 | 16/09/2023 | CCF-1001 | BSTR_23453 | BS 1200R20 G580 THI | 5.00 | 1,880.00 | 9,400.00 | ||
17 | SUM | 9,400.00 | ||||||||
SV |
COL.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | ITEM | DATE | CUSTOMER | INV.NO | BRAND | QTY | PRICE | TOTAL | ||
2 | 1 | 10/06/2023 | CCF-1002 | BSJ_23444 | BS 215/60R16 ER30 JAP | 4.00 | 430.00 | 1,720.00 | ||
3 | SUM | 1,720.00 | ||||||||
4 | 1 | 10/06/2023 | CCF-1002 | BSJ_23445 | GO 1200R20 AZX0026 CHI | 2.00 | 955.00 | 1,910.00 | ||
5 | SUM | 1,910.00 | ||||||||
6 | 1 | 15/09/2023 | CCF-1001 | BSJ_23446 | GO 1200R20 AZX0026 CHI | 2.00 | 950.00 | 1,900.00 | ||
7 | 2 | 15/09/2023 | CCF-1001 | BSJ_23446 | GO 1200R21 AZ0027 CHI | 3.00 | 1,000.00 | 3,000.00 | ||
8 | SUM | 4,900.00 | ||||||||
9 | 1 | 15/09/2023 | CCF-1000 | BSJ_23447 | BS 1200R20 G580 JAP | 1.00 | 2,000.00 | 2,000.00 | ||
10 | 2 | 15/09/2023 | CCF-1000 | BSJ_23447 | BS 1200R20 G580 THI | 1.00 | 2,000.00 | 2,000.00 | ||
11 | 3 | 15/09/2023 | CCF-1000 | BSJ_23447 | BS 1200R20 R187 JAP | 1.00 | 2,000.00 | 2,000.00 | ||
12 | SUM | 6,000.00 | ||||||||
SR |
COL.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | ITEM | DATE | CUSTOMER | INV.NO | BRAND | QTY | PRICE | TOTAL | ||
2 | 1 | 15/06/2023 | CCF-1000 | VSTR_23444 | BS 750R16 R230 JAP | 1.00 | 500.00 | 500.00 | ||
3 | SUM | 500.00 | ||||||||
4 | 1 | 15/09/2023 | CCF-1000 | VSTR_23445 | GO 1200R20 AZ0183 | 1.00 | 1,000.00 | 1,000.00 | ||
5 | SUM | 1,000.00 | ||||||||
6 | 1 | 15/09/2023 | CCF-1001 | VSTR_23446 | BS 1200R20 G580 JAP | 1.00 | 1,800.00 | 1,800.00 | ||
7 | 2 | 15/09/2023 | CCF-1001 | VSTR_23446 | BS 1200R20 G580 JAP | 1.00 | 1,800.00 | 1,800.00 | ||
8 | SUM | 3,600.00 | ||||||||
9 | 1 | 16/09/2023 | CCF-1001 | VSTR_23447 | BS 215/60R16 ER30 JAP | 4.00 | 400.00 | 1,600.00 | ||
10 | SUM | 1,600.00 | ||||||||
11 | 1 | 16/09/2023 | CCF-1001 | VSTR_23448 | BS 1200R20 R187 JAP | 1.00 | 1,800.00 | 1,800.00 | ||
12 | SUM | 1,800.00 | ||||||||
13 | 1 | 16/09/2023 | CCF-1000 | VSTR_23449 | BS 1200R20 G580 THI | 2.00 | 1,880.00 | 3,760.00 | ||
14 | SUM | 3,760.00 | ||||||||
VS |
COL.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | ITEM | DATE | CUSTOMER | INV.NO | BRAND | QTY | PRICE | TOTAL | ||
2 | 1 | 10/06/2023 | CCF-1002 | RSS_23222 | BS 215/60R16 ER30 | 2.00 | 430.00 | 860.00 | ||
3 | SUM | 860.00 | ||||||||
4 | 1 | 10/06/2023 | CCF-1001 | BSJ_23445 | GO 1200R20 AZ0026 | 1.00 | 955.00 | 955.00 | ||
5 | SUM | 955.00 | ||||||||
6 | 1 | 15/09/2023 | CCF-1002 | BSJ_23446 | GO 1200R20 AZ0026 | 1.00 | 950.00 | 950.00 | ||
7 | 2 | 15/09/2023 | CCF-1002 | BSJ_23446 | GO 1200R21 AZ0027 | 2.00 | 1,000.00 | 2,000.00 | ||
8 | SUM | 2,950.00 | ||||||||
RS |
when I select sheet name from combobox1, select the header from combobox2 and write the ID is relating with the header in textbox3 then will populate data in listbox and sum colulmn QTY in textbox4 and sum column TOTAL in textbox5 like this
example SV sheets
when just select header and ID without sheet name will add column sheets names in third column in listbox
as to dates(textbox1,textbox2) should be when select sheet name and header or when just select header without sheet name .
I hope correct my error and improve based on my requirements.
thanks