adding range items to a listbox upon initialization


Posted by elizabeth on November 15, 2000 2:34 PM

I've been trying to get a ListBox to AddItems when it is initialized. When I put in text it works fine. But I can't figure out how to get it to pull the information from a named range on my worksheet. Any suggestions on how I can get it do do this?

Here is the code that works when it accepts text.
(where Choose is the UserForm and SelectPerson is the ListBox)
Sub Choose_Initialize()
With SelectPerson
.additem "jim"
.additem "joe"
End with

SelectPerson.ListIndex = 0
End Sub


Thanks!!!
E



Posted by Tim Francis-Wright on November 16, 2000 1:31 PM

SelectPerson.ListIndex = 0

You'll want to use the RowSource property:
Sub Choose_Initialize()

With SelectPerson
.RowSource = "Sheet1!a1:a5" 'or whatever the range should be
End With
SelectPerson.ListIndex = 0

End Sub


HTH