Listbox1 selection to populate Listbox2

ReliableEngineer

New Member
Joined
Oct 26, 2017
Messages
3
Hey there people,

I am working on a userform to monitor repeat defects on our fleet of aircraft. I want this form to display the defect information in listbox2 when you select the appropriate watchlist item in listbox1.

So far I am stuck on making listbox1 display all items on the "Register' worksheet. I need to figure how to show only the Fleet type, Registration or ATA combobox search options, but that's for a future thread. Here I only want to see the defect info in listbox2 when I make a selection in listbox1.

Could someone please help?

Cheers.

Here is my code so far:

Code:
Private Sub UserForm_Initialize()
'Empty RegoComboBox
 RegoComboBox.Clear
 
'Fill RegoCombobox
 Me.RegoComboBox.List = Worksheets("Data").Range("B2:B54").Value
 
'Empty FleetTypeComboBox
 FleetTypeComboBox.Clear
 
'Fill FleetTypeCombobox
 Me.FleetTypeComboBox.List = Worksheets("Data").Range("D2:D7").Value
 
'Empty ActiveRWLItemsListBox
 ActiveRWLItemsListBox.RowSource = ""
  
'Empty ActiveRWLItemsListBox
 ActiveRWLItemsListBox.Clear
'Empty ATAComboBox
 ATAComboBox.Clear
 
 'Fill ATAComboBox
 Me.ATAComboBox.List = Worksheets("Data").Range("C2:C38").Value
 
 'Uncheck DataCheckBoxes
 IncludeClosedCheckBox.Value = False
'Set Focus on FleetTypeComboBox
 FleetTypeComboBox.SetFocus

End Sub
Private Sub SearchActiveCommandButton_Click()
    Dim i               As Long
    Dim n               As Long
    Dim Str             As String
     
    Str = Me.RegoComboBox.Value
    n = Me.ActiveRWLItemsListBox.ListCount
    For i = 0 To n - 1
        If Left(Me.ActiveRWLItemsListBox.List(i), Len(Str)) = Str Then
            Me.ActiveRWLItemsListBox.ListIndex = i
            Exit Sub
        End If
    Next i
     
ActiveRWLItemsListBox.RowSource = Range("ActiveRWLItems").Address
ListFilter = "Select [RegoData].[RegoData] " & _
"FROM RegoData" & _
"WHERE [RegoData].[ReportFleetType] = '" & Me.FleetTypeComboBox.Value & "'"
End Sub
 
Last edited by a moderator:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this:
When you click on some value in ListBox1 this value will be added to Listbox2

Code:
Private Sub ListBox1_Click()
ListBox2.AddItem ListBox1.Value
End Sub
 
Upvote 0
Thanks for the suggestion. Unfortunately this didn't work.

I should have specified in my code which listbox was which.

"ActiveRWLItemsListBox" is listbox1 and "DiscrepanciesListBox" is listbox2.
The rows populated in ActiveRWLItemsListBox are unique with Column A containing the sequential id code on the "Register" worksheet.
The DiscrepanciesListBox ideally will take note of the unique id for the selection in the first listbox and display the rows that have that same unique code in column A of the "IASDefects" worksheet.
 
Upvote 0
Well if your trying to learn vba modify my script to meet your needs. Just change the names in my script to meet your needs.

Your question was:

I want this form to display the defect information in listbox2 when you select the appropriate watchlist item in listbox1.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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