VBA EXCEL - Multiple Listbox With MultiSelect

Piscesto

New Member
Joined
Aug 29, 2024
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
I've 2 listboxes, both with MultiSelect option. The 1st listbox is LstCustomer and the 2nd listbox is LstTransaction.
In LstCustomer it only showing the customer name and in LstTransaction it showing the customer name, invoice number, and transaction date.

How do I make it so that when a customer name in LstCustomer (one or more rows) is selected, the data in LstTransaction that has the same data (customer name) is also selected?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Assuming LstTransaction is a multi-column listbox and customer name is the first column:

VBA Code:
Private Sub LstCustomer_Change()

    Dim c As Long, t As Long
    
    For c = 0 To LstCustomer.ListCount - 1
        For t = 0 To LstTransaction.ListCount - 1
            If LstTransaction.List(t, 0) = LstCustomer.List(c) Then
                LstTransaction.Selected(t) = LstCustomer.Selected(c)
            End If
        Next
    Next
        
End Sub
 
Upvote 0
Solution
Assuming LstTransaction is a multi-column listbox and customer name is the first column:

VBA Code:
Private Sub LstCustomer_Change()

    Dim c As Long, t As Long
  
    For c = 0 To LstCustomer.ListCount - 1
        For t = 0 To LstTransaction.ListCount - 1
            If LstTransaction.List(t, 0) = LstCustomer.List(c) Then
                LstTransaction.Selected(t) = LstCustomer.Selected(c)
            End If
        Next
    Next
      
End Sub
Thanks for you answer.
It Helps and works.
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
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