ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Linking Cells to ListBox - How? (https://www.excelbanter.com/excel-programming/286312-linking-cells-listbox-how.html)

William C. Smith

Linking Cells to ListBox - How?
 
Is it possible to link a range of cells to a listbox: i.e. when code
executes a show method the list box displays the contents of the linked
cells.

Bill

shockley

Linking Cells to ListBox - How?
 
William,

At design-time you can set the 'RowSource' property of the listbox in the
properites window of the listbox to a named range of the Workbook. Or you
can do the same at runtime using the listbox's RowSource property, eg.,

Form1.Listbox1.RowSource = "MyRange"

Or, define and name the range at runtime, eg.,

Range("A1:A10").Name = "MyRange"
Form1.Listbox1.RowSource = "MyRange"
Form1.Show

Or, if you pefer not to name the range (naming the range results in the
workbook containing that named range), you can just define the range and
fill the listbox item by item, eg.,

Dim cell As Range
For each cell in Range("A1:A10")
Form1.Listbox1.AddItem (cell.Value)
Next cell
Form1.Show

HTH,
Shockley

"William C. Smith" <wcsmithx*xieee.org wrote in message
...
Is it possible to link a range of cells to a listbox: i.e. when code
executes a show method the list box displays the contents of the linked
cells.

Bill




William C. Smith

Linking Cells to ListBox - How?
 
"shockley" wrote in news:4lnHb.31879$d36.27989
@news01.roc.ny:

At design-time you can set the 'RowSource' property of the listbox in the


Thank you. I had been to the Properties Window, but how to use it is not
obvious. After your help I still had to experiment to find the right way to
insert a name in the value field. Help was no help.

Again Thank You.


All times are GMT +1. The time now is 07:46 PM.

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