View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default populating a listbox from an array

Graham,
All these work for me:
Private Sub CommandButton1_Click()
Dim MyArray As Variant
Dim StrArray(9) As String
Dim i As Long

Const MyValues As String = "Val 1,Val 2,Val 3,Val 4,Val 5"

With ListBox1
.Clear
.List = Split(MyValues, ",")
.ListIndex = 0

MyArray = Split(MyValues, ",")
.Clear
.List = MyArray
.ListIndex = 0

For i = 0 To 9
StrArray(i) = "String array " & i
Next
.Clear
.List = StrArray
.ListIndex = 0
End With
End Sub

NickHK

"Graham Whitehead" wrote in message
...
Hi, I know there must be a fairly simple solution to this one but I cant
quite get the syntax right. Basically I have a set of values stored in an
array an I simply want to populate the list box with these. one article on
the microsoft website simply gave:

VBA:
'Assign the array to the listbox
ListBox1.List = LArray However, I get an object required error. Can anyone
help me out? Thanks.