list box

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
83
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
hi
I have two listboxes in my form, the first is fixed and the second is variable
How can I select any of the options associated with the first listbox so that its sub-set is displayed in the second listbox
Untitled2.png
 
To do this I used the following code
VBA Code:
Private Sub UserForm_Initialize()
    Me.ListBox1.List = Sheet1.Range("A1:A9").Value
End Sub

Private Sub UserForm_Initialize()

With ListBox1
    .AddItem "100"
    .AddItem "200"
    .AddItem "300"
End With

End Sub


Private Sub ListBox1_Change()

Dim index As Integer
index = ListBox1.ListIndex

ListBox2.Clear

Select Case index
    Case Is = 0
        With ListBox2
            .AddItem "101"
            .AddItem "102"
            .AddItem "103"
        End With
    Case Is = 1
        With ListBox2
            .AddItem "201"
            .AddItem "202"
            .AddItem "203"
        End With
    Case Is = 2
        With ListBox2
            .AddItem "301"
            .AddItem "302"
            .AddItem "303"
        End With
End Select

End Sub

But in the datasheet each group is listed as list01,list02,..
How do I call these lists in the form?
 
Upvote 0
try
Code:
Private Sub UserForm_Initialize()
    With Sheets("data").[a1].CurrentRegion
        Me.ListBox1.List = Application.Index(.Value, 0, 1)
    End With
End Sub

Private Sub ListBox1_Click()
    With Sheets("data").[a1].CurrentRegion
        Me.ListBox2.Column = .Rows(Me.ListBox1.ListIndex + 1).Range("b1").Resize(, .Columns.Count - 1).Value
    End With
End Sub
 
Upvote 0
try
Code:
Private Sub UserForm_Initialize()
    With Sheets("data").[a1].CurrentRegion
        Me.ListBox1.List = Application.Index(.Value, 0, 1)
    End With
End Sub

Private Sub ListBox1_Click()
    With Sheets("data").[a1].CurrentRegion
        Me.ListBox2.Column = .Rows(Me.ListBox1.ListIndex + 1).Range("b1").Resize(, .Columns.Count - 1).Value
    End With
End Sub
This is almost like on my request
But I want to be like the picture below
 

Attachments

  • Untitled3.png
    Untitled3.png
    42.6 KB · Views: 4
Upvote 0
What is the logic to populate ListBox2 to such strange list that doesn't exist in the table?
my guess, ListBox1_Click event code
Rich (BB code):
Private Sub ListBox1_Click()
    With Sheets("data").[a1].CurrentRegion
        Me.ListBox2.List = .Columns(Me.ListBox1.ListIndex + 2).Range("a2").Resize(.Rows.Count - 1).Value
    End With
End Sub
 
Upvote 0

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