ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Populate a list box from a worksheet range (https://www.excelbanter.com/excel-programming/355535-populate-list-box-worksheet-range.html)

Peter Rooney

Populate a list box from a worksheet range
 
Good morning, all.

I'm sorry to say I'm now turning my attention to userforms (collective groan
from both hemispheres)

This one's quite easy, though (well, for SOMEone out there) Here's my code
to add some items to a listbox:

Private Sub UserForm_Initialize()
With lstEmployees
.AddItem "Dave"
.AddItem "Rob"
.AddItem "Greg"
.AddItem "Christina"
.AddItem "Mark"
End With
cmdAdd.Enabled = False
cmdRemove.Enabled = False
cmdRemoveAll.Enabled = False
End Sub

However, how to I popiulate the listbox with, say, A1:A6 (or a named range)
from (say) Shee t2?

Thanks in advance

Pete



gti_jobert[_54_]

Populate a list box from a worksheet range
 

Code:
--------------------

i = 3
Do
With lstBox
.AddItem Cells(i, 1).Value
End With
i = i + 1
Loop Until Cells(i, 1).Value = ""

--------------------


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=520486


Peter Rooney

Populate a list box from a worksheet range
 
This works fine - easy when you know how!
This enabled me to work out how to pupulate from a named renga, too, so
thanks a lot! :-)

Pete

Private Sub UserForm_Initialize()
Dim ListCell As Range
For Each ListCell In Range("CarList")
lstEmployees.AddItem ListCell.Value
Next
End Sub


"gti_jobert" wrote:


Code:
--------------------

i = 3
Do
With lstBox
.AddItem Cells(i, 1).Value
End With
i = i + 1
Loop Until Cells(i, 1).Value = ""

--------------------


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=520486




All times are GMT +1. The time now is 03:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com