select range from combobox to populate data in listbox

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hi
this code for DanteAmore and I modified to fit with my requirements but I faild
my goal select the header from combobox1 by matching with header in column G then should populate data in the listbox for the range is relating with the header in columns (F:I) inside the sheet. .
VBA Code:
Option Explicit
Dim a As Variant

Sub FilterData()
  Dim txt1 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 ComboBox1.Value = "" Then txt1 = a(I, 2) Else txt1 = ComboBox1.Value
    
    If LCase(a(I, 2)) Like LCase(txt1) & "*" Then
      k = k + 1
      For j = 1 To 4
        b(k, j) = a(I, j)
      Next
    End If
  Next
  If k > 0 Then ListBox1.List = b
End Sub

Private Sub ComboBox1_Change()
 Call FilterData
End Sub

Private Sub UserForm_Activate()
  a = Sheets("RANGES").Range("F2:I" & Sheets("RANGES").Range("G" & Rows.Count).End(3).Row).Value
End Sub
data in sheet
RANGES.xlsm
ABCDEFGHI
1SRSR
2ITEMDATETYPETOTALITEMDATENOT PAIDPAID
3110/06/2023NOT PAID7,720.00110/06/20239,720.0010,810.00
4210/06/2023NOT PAID2,000.00211/06/20237,000.000.00
5310/06/2023PAID6,810.00SUM16,720.0010,810.00
6410/06/2023PAID4,000.00
7511/06/2023NOT PAID7,000.00SVR
8SUM27,530.00ITEMDATENOT PAIDPAID
9110/06/20235,720.0014,040.00
10SVR211/06/202313,230.000.00
11ITEMDATETYPETOTAL312/06/20230.0015,000.00
12110/06/2023NOT PAID5,720.00SUM18,950.0029,040.00
13210/06/2023PAID14,040.00
14311/06/2023NOT PAID1,230.00SDE
15411/06/2023NOT PAID12,000.00ITEMDATENOT PAIDPAID
16512/06/2023PAID14,000.00110/06/20230.005,000.00
17612/06/2023PAID1,000.00211/06/20232,200.002,000.00
18SUM47,990.00312/06/20233,000.000.00
19SUM5,200.007,000.00
20
21SDEFGR
22ITEMDATETYPETOTALITEMDATENOT PAIDPAID
23110/06/2023PAID4,000.00110/06/20230.002,500.00
24210/06/2023PAID1,000.00211/06/20231,100.000.00
25311/06/2023PAID2,000.00312/06/20239,200.000.00
26411/06/2023NOT PAID2,200.00SUM10,300.002,500.00
27512/06/2023NOT PAID3,000.00
28SUM12,200.00
29
30
31FGR
32ITEMDATETYPETOTAL
33110/06/2023PAID1,200.00
34210/06/2023PAID1,300.00
35311/06/2023NOT PAID1,100.00
36412/06/2023NOT PAID2,200.00
37512/06/2023NOT PAID7,000.00
38SUM12,800.00
39
RANGES
Cell Formulas
RangeFormula
D8,D38,D28D8=SUM(D3:D7)
D18D18=SUM(D12:D17)


here example when select the header in combobox1
IMAGE.PNG
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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