View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Fill values into a listbox matching selected values from a combobox

Jon,

I think this is what you want

Private Sub cboMusclegroup_Click()
frmExercise.lblMuscleGroupID.Caption = frmExercise.cboMusclegroup.ListIndex
'
Dim WS As Worksheet
Dim WSRow As Long
Dim i As Long
'
frmExercise.lstExercise.Clear
'
Set WS = Application.ActiveWorkbook.Worksheets("exercise")
'
'Finds the last row in column B containing a value
WSRow = WS.Cells(Cells.Rows.Count, "B").End(xlUp).Row

Me.lstExercise.Clear
For i = 1 To WSRow
If WS.Cells(i, "C").Value = Me.cboMusclegroup.Value Then
lstExercise.AddItem WS.Cells(i, "B")
End If
Next i
If Me.lstExercise.ListCount 0 Then
Me.lstExercise.ListIndex = 0
End If

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jon" wrote in message
...

Hi
I have 2 worksheets (musclegroup and exercise)
I loop in the values from musclegroup into a combobox,
the combobox listindex is the same as the ID(A).

Now I want to fill up the exercises(column B in worksheet exercise) into
the frmExercise.lstExercise
that correspond to the musclegroup I select in frmExercise.cboMusclegroup.

Is there a simply way
Regards
Jon

Follow the link below, explains and shows the userform and worksheets
http://www.johak.se/index.html