Reafidy
Administrator
Likes Received4Points13,393Trophies2Posts4,377
- Dec 5th 2007
- #4
Re: Retrieve Selected Items In Listbox
This will loop through the items in the listbox and return them to the worksheet.
Code
- Private Sub CommandButton1_Click[]
- Dim lItem As Long
- For lItem = 0 To Me.ListBox1.ListCount - 1
- If Me.ListBox1.Selected[lItem] Then
- Range["A" & Rows.Count].End[xlUp].Offset[1].Value = Me.ListBox1.List[lItem]
- End If
- Next lItem
- End Sub
Andy Pope
OzMVP [Roobarb]
Likes Received1Points33,975Trophies2Posts11,304
- Dec 6th 2007
- #9
Re: Retrieve Selected Items In Listbox
As the control is on a worksheet you need to include a reference to it.
[vba]
Sub GetListboxItems[]
Dim iListCount As Integer
Dim iRow As Integer
Dim rStartCell As Range
Set rStartCell = Sheets["Sheet1"].Range["F65536"].End[xlUp].Offset[1, 0]
With ActiveSheet.Shapes["ListBox1"].OLEFormat.Object.Object
For iListCount = 0 To .ListCount - 1
If .Selected[iListCount] = True Then
.Selected[iListCount] = False
iRow = iRow + 1
rStartCell.Offset[iRow].Value = .List[iListCount, 0]
End If
Next iListCount
End With
Set rStartCell = Nothing
End Sub
[/vba]
[h4]Cheers
Andy[/h4]