Fill values into a listbox matching selected values from a combobox

J

Jon

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
 
B

Bob Phillips

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)
 
T

Tom Ogilvy

Private Sub cboMuscleGroup_Click()
frmExcercise.lstExercise.Clear
for each cell in worksheets("Exercise").Range("A1:A10)
if cell.Value = frmExcercise.cboMuscleGroup.Value then
frmExcercise.lstExercise.AddItem cell.offset(0,1)
end if
Next
End Sub

Assumes A1:B10 is a list with musclegroup in column A and exercise in column
B
 
J

Jon

Jon said:
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

Thanks Guys
Works perfectly
 
T

Tom Ogilvy

Didn't see your link at the bottom of the message, or mine might have been
more tailored.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top