For each picked entitiy in a list box...

C

Ctech

Hi I have never used a list box, with VBA before..

How do i do it when the list box can have several marked choices...

i want my macro to add text is certain cells, depending on what i
picked of the list in the list box.

Thans
 
P

paul.robinson

Hi
If you have a form called myForm with a multiselection listbox called
myListbox then

With myForm.mylistBox
'Get the selected data in the ListBox
For i = 0 To .ListCount - 1
'for each Group in the list
If .Selected(i) Then
'do your thing here
End If
Next i
End With

regards
Paul
 
C

Ctech

See code below:

I have a list box, named cboSecondary which is in Sheet "combo".
non of this is actuall yin a form.
 
G

Guest

This worked for me. I assume cboSecondary is a LISTBOX (not a combobox) with
the multiselect property set to True

Sub Update_task_part()
' This macro adds the tasks picked in the List Box and adds them to the
' Tasks revenue part of the form
' Created by Christian Simonsen 21/03/06

Dim mRows As Long
Dim i As Long
Dim Msg As String

' hides/unhides the required rows depending on the number of tasks
' picked
mRows = 0
With cboSecondary
For i = 0 To .ListCount - 1
If .Selected(i) Then mRows = mRows + 1
Next
End With
Range("list_rev").EntireRow.Hidden = False
mRows = 10 - mRows + 1
Range("list_rev").Rows("" & _
mRows & ":10").EntireRow.Hidden = True


' Gets the task numbers for the rows
With cboSecondary
For i = 0 To .ListCount - 1
If .Selected(i) Then
Msg = Msg & .List(i) & vbCrLf
End If
Next i
End With

If Len(Msg) = 0 Then
Msg = "No items selected"
Else
MsgBox Msg
End If

End Sub
 

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