Consulting

Results 1 to 3 of 3

Thread: Solved: Fill 2-column list

  1. #1
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location

    Question Solved: Fill 2-column list

    I need to fill a list with 2-columns depending on a parameter. The parameters values are in range A2:A12. The first column shold be filled from the data in range B2:B12. The second column should be filled from the data sitting in C2:C12.

    The parameters are options. Selecting one option should loop through the range A2:A12 and pick the right value from range B2:C12. Can you help with the code?

    I attach here the file with all the data and List and options in it that I am working on.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Add this code to the shee module

    [vba]

    Private Sub OptionButton2_Click()
    FillList Me.OLEObjects("OptionButton2").Object.Caption
    End Sub

    Private Sub OptionButton1_Click()
    FillList Me.OLEObjects("OptionButton1").Object.Caption
    End Sub

    Private Sub OptionButton3_Click()
    FillList Me.OLEObjects("OptionButton3").Object.Caption
    End Sub

    Private Sub OptionButton4_Click()
    FillList Me.OLEObjects("OptionButton4").Object.Caption
    End Sub

    Private Sub FillList(val As String)
    Dim iLastRow As Long
    Dim i As Long

    iLastRow = Me.Cells(Me.Rows.Count, "A").End(xlUp).Row
    With Me.OLEObjects("ListBox1").Object
    .Clear
    For i = 1 To iLastRow
    If Me.Cells(i, "A").Value = val Then
    .AddItem Me.Cells(i, "B").Value
    .List(.ListCount - 1, 1) = Me.Cells(i, "C").Value
    End If
    Next i
    End With
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.

  3. #3
    VBAX Regular
    Joined
    Dec 2004
    Posts
    93
    Location
    It works! Thanks a lot xld.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •