PDA

View Full Version : Solved: Fill 2-column list



Kaizer
09-10-2006, 02:48 AM
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.

Bob Phillips
09-10-2006, 03:01 AM
Add this code to the shee module



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


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.

Kaizer
09-10-2006, 03:26 AM
It works! Thanks a lot xld. :)