View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Loading array into list box

Use this event in the userform module

Private Sub UserForm_Initialize()
Me.ListBox1.List = Sheet1.Range("A1:A4").Value
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"r wilcox" wrote in message ...
I'm trying to load an array into a list box. When I execute the following
macro, it tells me that I have a subscript out of range for the AddItem code.

Sub PopulateListBox()
Dim MyArray As Variant
Dim Ctr As Integer
MyArray = Sheet1Range("A1:A4").Value
For Ctr = LBound(MyArray) To UBound(MyArray)
UserForm1.ListBox1.AddItem MyArray(Ctr)
Next
UserForm1.Show
End Sub