I am trying to place selected items from a listbox (form control) into an array. I know just enough to be dangerous. The follownig code was lifted directly form a previous posting (ref Andrew Poulsom):
Sub test()
Dim i As Integer
Dim Msg As String
For i = 0 To ListBox7.ListCount - 1
If ListBox7.Selected(i) Then
Msg = Msg & ListBox7.List(i) & vbCrLf
End If
Next i
MsgBox "Selected items are:" & vbCrLf & Msg
End Sub
The only change is it is ListBox7, because I keep trying to redo this. when insert a listbox and go to assign it to a macro it auto fills the macro name as ListBox#_Change. So I am assuming the listbox would be named as such in any code. However, when i run the above code I get "Run-time error '424': Object required".
So, what am I doing wrong? The ultimate goal is to add selected items into an array. Thanks.
Sub test()
Dim i As Integer
Dim Msg As String
For i = 0 To ListBox7.ListCount - 1
If ListBox7.Selected(i) Then
Msg = Msg & ListBox7.List(i) & vbCrLf
End If
Next i
MsgBox "Selected items are:" & vbCrLf & Msg
End Sub
The only change is it is ListBox7, because I keep trying to redo this. when insert a listbox and go to assign it to a macro it auto fills the macro name as ListBox#_Change. So I am assuming the listbox would be named as such in any code. However, when i run the above code I get "Run-time error '424': Object required".
So, what am I doing wrong? The ultimate goal is to add selected items into an array. Thanks.