Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Fill a listbox with data from variable range

Hi all,

I'm trying to add items to a listbox, from a source that changes.
The values start from range B4. There can be as little as 5 cells to 36
cells of data that i need to add into the listbox.

I've tried to define the range (i.e. rng =
sheets("Data").range("B4").Selection.End(xlDown)) and get the listbox to pick
the values up from that range;
and have tried a looping statement to pick up cells from B4 until it hits a
blank cell.

The sheet with the data is hidden, and im trying not to use any select or
activate commands to fill the listbox.

Can anyone please help.
Cheers.
Al

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Fill a listbox with data from variable range

Hi Al

Assuming the listbox is on a UserForm you could try something like the
following when you open the UserForm.....

Private Sub UserForm_Initialize()
Dim r As Range, c As Range
With Sheets("Data")
Set r = .Range(.Range("B4"), .Range("B" & Rows.Count).End(xlUp))
For Each c In r
ListBox1.AddItem c
Next c
End With
End Sub

--
XL2002
Regards

William



"Al" wrote in message
...
| Hi all,
|
| I'm trying to add items to a listbox, from a source that changes.
| The values start from range B4. There can be as little as 5 cells to 36
| cells of data that i need to add into the listbox.
|
| I've tried to define the range (i.e. rng =
| sheets("Data").range("B4").Selection.End(xlDown)) and get the listbox to
pick
| the values up from that range;
| and have tried a looping statement to pick up cells from B4 until it hits
a
| blank cell.
|
| The sheet with the data is hidden, and im trying not to use any select or
| activate commands to fill the listbox.
|
| Can anyone please help.
| Cheers.
| Al
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Fill a listbox with data from variable range

Thanks William.

Setting up the range line was where i was having trouble. Your's works
fantastically.
Thanks heaps.

Al.


"William" wrote:

Hi Al

Assuming the listbox is on a UserForm you could try something like the
following when you open the UserForm.....

Private Sub UserForm_Initialize()
Dim r As Range, c As Range
With Sheets("Data")
Set r = .Range(.Range("B4"), .Range("B" & Rows.Count).End(xlUp))
For Each c In r
ListBox1.AddItem c
Next c
End With
End Sub

--
XL2002
Regards

William



"Al" wrote in message
...
| Hi all,
|
| I'm trying to add items to a listbox, from a source that changes.
| The values start from range B4. There can be as little as 5 cells to 36
| cells of data that i need to add into the listbox.
|
| I've tried to define the range (i.e. rng =
| sheets("Data").range("B4").Selection.End(xlDown)) and get the listbox to
pick
| the values up from that range;
| and have tried a looping statement to pick up cells from B4 until it hits
a
| blank cell.
|
| The sheet with the data is hidden, and im trying not to use any select or
| activate commands to fill the listbox.
|
| Can anyone please help.
| Cheers.
| Al
|



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range of data is variable... Tom Mackay Charts and Charting in Excel 4 September 26th 06 11:16 PM
Setting up a validation of data listbox to provide the unique items within a range [email protected] Excel Worksheet Functions 8 July 30th 06 09:00 AM
Variable data range help low98 Charts and Charting in Excel 3 January 11th 06 06:46 AM
Set Data Range by Variable MJSlattery Excel Discussion (Misc queries) 4 June 10th 05 07:48 AM
.ListFillRange as Variable ? in Listbox [email protected] Excel Programming 1 November 14th 03 03:29 AM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"