no experience for populate data in listbox based on selected item from another listbox

Amer Omar

New Member
Joined
Jan 27, 2024
Messages
21
Office Version
  1. 2019
Platform
  1. Windows
Hi experts,
I search too much to populate data in listbox based on selected item from another listbox.
all of what I found it just by txtbox . I don't wanted .
I have two simple codes
first show data in listbox2 based on Expenses Detailes sheet as in image1
VBA Code:
Private Sub UserForm_Initialize()
   Dim LastRow As Long
   
   
    LastRow = Range("A" & Rows.Count).End(xlUp).Row    '<---- ??????
    With ListBox2
        .ColumnCount = 7
        .ColumnWidths = "70;70;170;130;70;70;70"
        .List = Range("A2:G" & LastRow).Value
    End With
    
End Sub

PP1.PNG




Form
ABCDEF
1DATEExchange authorization numberExpense NameExpense DescribtionAccount numberAmount
201/01/2024A00hospitalityLunch for three personssafe1300.00
301/01/2024A01StationeryFiles & Mony RubberMain Safe250.00
401/01/2024A02maintenanceTires & Discosafe11,200.00
502/01/2024A03maintenanceElectricity Carsafe12,500.00
602/01/2024A04hospitalityLunch for Four personsMain Safe430.00
702/01/2024A05StationeryPaper for PrinterMain Safe100.00
803/01/2024A06StationeryTransparent filessafe1120.00
903/01/2024A07Salaries of employees and workersTen Employees & workersMuth Bank20,000.00
1003/01/2024A08Goods packing workersThree Truckssafe1900.00
1103/01/2024A09hospitalityLunch for Six personssafe1750.00
1204/01/2024A10Office FurnitureThree Tables For OffieMuth Bank1,500.00
1304/01/2024A11Shop rentAdvanced monthMuth Bank7,600.00
1404/01/2024A12hospitalityLunch for Two personsMain Safe275.00
1504/01/2024A13maintenanceMechanicsafe11,670.00
Expenses Detailes


second image when select optionbutton1 based on Detailes sheet then will populate data in listbox1

VBA Code:
Private Sub OptionButton1_Click()
Dim LastRow As Long
   Dim ws As Worksheet
   Set ws = Sheets("Detailes")
   If OptionButton1.Value = True Then
   
    LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row    '<---- ??????
    With ListBox1
        .ColumnCount = 1
        .List = ws.Range("A2:A" & LastRow).Value
    End With
    End If
End Sub

PP2.PNG


Form
A
1EXPENSES NAME
2hospitality
3maintenance
4Personal withdrawals
5Cleaning materials
6Stationery
7Shop rent
8Salaries of employees and workers
9Renting the transportation of goods
10Workers unloading goods
11Goods packing workers
12Goods shipping costs
13Office Furniture
14Laptop & Office Furniture
15Office Furniture
16Cars
Detailes


what I expect as in picture.
should match selected item from listbox1 with the column(3) in listbox2 and filter data in listbox2 for the select item from listbox1 like this
PP3.PNG

I have no Experience for that ,I look forward from the expert to do that with considering data could be 10000 rows in Expenses Detailes.
Thanks.
 
Hi John again,
I made sure there is no problem as you suggest in post#3 .(y)
I appreciate for your time to help me.;)
thank you for everything .:)
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

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