B
battists
Hello all,
I'm a novice at VBA, struggling with an unhelpful listbox. I'm tryin
to ultimately write code that populates an array with values picke
from a multi-select list box.
While testing, here's what I've done:
I created a brand new spreadsheet, created a list box using the Contro
Toolbox called lbServers.
I then created a macro that only does the following:
Code
-------------------
Sub Test()
Dim Servers(10) As String
Set MyListBox = Sheet1.lbServers
y = 1
For x = 1 To MyListBox.Items.Count '<---problem spot
If MyListBox.Selected(x) Then
Servers(y) = MyListBox.Columns(0, x)
y = y + 1
End If
Next x
End Sub
-------------------
When I step through this code, it sets MyListBox with a Type o
Variant/Object/ListBox. This object does not have an Items propert
(collection?) when I look at it in the Locals window. If I kee
stepping, I reach the problem spot, and it returns "Object does no
support this property or method."
It seems that for some reason it's not recognizing the object as
ListBox. AutoComplete finds the control in Sheet1, but if I typ
"Sheet1.lbServers." it can't find any properties at all.
Any suggestions? This is on Excel 2003.
Thanks!
Stev
I'm a novice at VBA, struggling with an unhelpful listbox. I'm tryin
to ultimately write code that populates an array with values picke
from a multi-select list box.
While testing, here's what I've done:
I created a brand new spreadsheet, created a list box using the Contro
Toolbox called lbServers.
I then created a macro that only does the following:
Code
-------------------
Sub Test()
Dim Servers(10) As String
Set MyListBox = Sheet1.lbServers
y = 1
For x = 1 To MyListBox.Items.Count '<---problem spot
If MyListBox.Selected(x) Then
Servers(y) = MyListBox.Columns(0, x)
y = y + 1
End If
Next x
End Sub
-------------------
When I step through this code, it sets MyListBox with a Type o
Variant/Object/ListBox. This object does not have an Items propert
(collection?) when I look at it in the Locals window. If I kee
stepping, I reach the problem spot, and it returns "Object does no
support this property or method."
It seems that for some reason it's not recognizing the object as
ListBox. AutoComplete finds the control in Sheet1, but if I typ
"Sheet1.lbServers." it can't find any properties at all.
Any suggestions? This is on Excel 2003.
Thanks!
Stev