Hi,
I am clearly not understanding how one declaring and using listboxes in Excel. So a novice needs some help here.
I am trying to create a ListBox, not ActiveX, where I have a list of items in the box. I would like to select several items and via a vba macro identify wihich one I have selected. I have created a ListBox (Form Controls) and populated the box with Worksheets("Menu").Shapes("FirstBox").ControlFormat.AddItem Value. I have named the listbox "FirstBox" and it is placed in worksheet "Menu". So good so far. Now I select a few items in the list. I would like to connect a macro that reads the selected items from the listbox. The code I am using is as follows
Sub FirstBox_Change()
Dim firstlist() As Variant
Dim FirstBox As Shape
Dim antal As Integer
Sheets("Menu").Select
selCount = -1
antal = FirstBox.ListCount
Sheets("Menu").Select
For i = 0 To FirstBox.ListCount - 1
If FirstBox.Selected(i) = True Then
selCount = selCount + 1
ReDim Preserve firstlist(selCount)
firstlist(selCount) = FirstBox.List(i)
End If
Next
End Sub
When I select an item in the listbox I get the following error message
"Run Time Error 91", "Object variable or With block variable not set"
I assume there is something wrong in my declarations.
What is missing or what am I doing wrong?
Many thanks
Stefan
I am clearly not understanding how one declaring and using listboxes in Excel. So a novice needs some help here.
I am trying to create a ListBox, not ActiveX, where I have a list of items in the box. I would like to select several items and via a vba macro identify wihich one I have selected. I have created a ListBox (Form Controls) and populated the box with Worksheets("Menu").Shapes("FirstBox").ControlFormat.AddItem Value. I have named the listbox "FirstBox" and it is placed in worksheet "Menu". So good so far. Now I select a few items in the list. I would like to connect a macro that reads the selected items from the listbox. The code I am using is as follows
Sub FirstBox_Change()
Dim firstlist() As Variant
Dim FirstBox As Shape
Dim antal As Integer
Sheets("Menu").Select
selCount = -1
antal = FirstBox.ListCount
Sheets("Menu").Select
For i = 0 To FirstBox.ListCount - 1
If FirstBox.Selected(i) = True Then
selCount = selCount + 1
ReDim Preserve firstlist(selCount)
firstlist(selCount) = FirstBox.List(i)
End If
Next
End Sub
When I select an item in the listbox I get the following error message
"Run Time Error 91", "Object variable or With block variable not set"
I assume there is something wrong in my declarations.
What is missing or what am I doing wrong?
Many thanks
Stefan