Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Populate a ListBox

I want to populate a list box using a range in a different workbook and
folder. Have tried many things and many code snipets from other sources to
no avail

I am sure I will have to load the RowSource in code when the form Initializes.
My list box name is lb_Contact
The other workbook is 'ContactInformation'
The range is 'ContactName'

Any help will let me sleep tonight.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Populate a ListBox

JB

Use the AddItem method instead of the RowSource property

http://www.dicks-blog.com/archives/2...stboxcombobox/


--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com

JB in Kansas wrote:
I want to populate a list box using a range in a different workbook
and folder. Have tried many things and many code snipets from other
sources to no avail

I am sure I will have to load the RowSource in code when the form
Initializes. My list box name is lb_Contact
The other workbook is 'ContactInformation'
The range is 'ContactName'

Any help will let me sleep tonight.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Populate a ListBox

Dick,
I have tried using AddItem but must be writing the code worng.

I have used this:
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2, 1000)

And this
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Range("ContactName")

Both give me an error message "Subscript out of range". What am I doing
wrong?

"Dick Kusleika" wrote:

JB

Use the AddItem method instead of the RowSource property

http://www.dicks-blog.com/archives/2...stboxcombobox/


--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com

JB in Kansas wrote:
I want to populate a list box using a range in a different workbook
and folder. Have tried many things and many code snipets from other
sources to no avail

I am sure I will have to load the RowSource in code when the form
Initializes. My list box name is lb_Contact
The other workbook is 'ContactInformation'
The range is 'ContactName'

Any help will let me sleep tonight.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Populate a ListBox

That is probably not a listbox error. My guess is that the workbook or the
worksheet is misspelled or missing. Try

MsgBox Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2, 1000)

and see if it errs too.

HTH. Bst wishes Harald

"JB in Kansas" skrev i melding
...
Dick,
I have tried using AddItem but must be writing the code worng.

I have used this:
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2, 1000)

And this
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Range("ContactName")

Both give me an error message "Subscript out of range". What am I doing
wrong?

"Dick Kusleika" wrote:

JB

Use the AddItem method instead of the RowSource property


http://www.dicks-blog.com/archives/2...stboxcombobox/


--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com

JB in Kansas wrote:
I want to populate a list box using a range in a different workbook
and folder. Have tried many things and many code snipets from other
sources to no avail

I am sure I will have to load the RowSource in code when the form
Initializes. My list box name is lb_Contact
The other workbook is 'ContactInformation'
The range is 'ContactName'

Any help will let me sleep tonight.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Populate a ListBox

JB

I agree with Harald that "information" looks mispelled. When you get that
sorted, you can use either of these methods:

lb_Contact.List =
Workbooks("ContactInformation").Worksheets("Contac t").Range("ContactName").Value

or

Dim rCell as Range
Dim rRng as Range

Set rRng =
Workbooks("ContactInformation").Worksheets("Contac t").Range("ContactName")

For Each rCell in rRng.Cells
lb_Contact.AddItem rRng.Value
Next rCell

--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com
Harald Staff wrote:
That is probably not a listbox error. My guess is that the workbook
or the worksheet is misspelled or missing. Try

MsgBox Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2,
1000)

and see if it errs too.

HTH. Bst wishes Harald

"JB in Kansas" skrev i melding
...
Dick,
I have tried using AddItem but must be writing the code worng.

I have used this:
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2, 1000)

And this
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Range("ContactName")

Both give me an error message "Subscript out of range". What am I
doing wrong?

"Dick Kusleika" wrote:

JB

Use the AddItem method instead of the RowSource property


http://www.dicks-blog.com/archives/2...stboxcombobox/


--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com

JB in Kansas wrote:
I want to populate a list box using a range in a different workbook
and folder. Have tried many things and many code snipets from
other sources to no avail

I am sure I will have to load the RowSource in code when the form
Initializes. My list box name is lb_Contact
The other workbook is 'ContactInformation'
The range is 'ContactName'

Any help will let me sleep tonight.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Populate a ListBox

Dick, I finally got back to work on this. This spelling was a typo in the
message.

I have tried your suggestions and using both methods I still get a 'Run Time
error 9' 'Sub-script out of range' message.

Just to make sure my spelling is correct the following three lines work
(note the change I had to make to the first line).

Windows("ContactInformation.xls").Activate
Worksheets("Contact").Select
Range("ContactName").Select

I copied and pasted the workbook name, sheet name and range name.

I am a little lost my skills at best are low-average and this is blowing my
mind.

"Dick Kusleika" wrote:

JB

I agree with Harald that "information" looks mispelled. When you get that
sorted, you can use either of these methods:

lb_Contact.List =
Workbooks("ContactInformation").Worksheets("Contac t").Range("ContactName").Value

or

Dim rCell as Range
Dim rRng as Range

Set rRng =
Workbooks("ContactInformation").Worksheets("Contac t").Range("ContactName")

For Each rCell in rRng.Cells
lb_Contact.AddItem rRng.Value
Next rCell

--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com
Harald Staff wrote:
That is probably not a listbox error. My guess is that the workbook
or the worksheet is misspelled or missing. Try

MsgBox Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2,
1000)

and see if it errs too.

HTH. Bst wishes Harald

"JB in Kansas" skrev i melding
...
Dick,
I have tried using AddItem but must be writing the code worng.

I have used this:
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Cells(2, 1000)

And this
lb_Contact.AddItem
Workbooks("ContactInfromation").Worksheets("Contac t").Range("ContactName")

Both give me an error message "Subscript out of range". What am I
doing wrong?

"Dick Kusleika" wrote:

JB

Use the AddItem method instead of the RowSource property


http://www.dicks-blog.com/archives/2...stboxcombobox/


--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com

JB in Kansas wrote:
I want to populate a list box using a range in a different workbook
and folder. Have tried many things and many code snipets from
other sources to no avail

I am sure I will have to load the RowSource in code when the form
Initializes. My list box name is lb_Contact
The other workbook is 'ContactInformation'
The range is 'ContactName'

Any help will let me sleep tonight.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Populate a ListBox

JB in Kansas wrote:
Dick, I finally got back to work on this. This spelling was a typo
in the message.

I have tried your suggestions and using both methods I still get a
'Run Time error 9' 'Sub-script out of range' message.

Just to make sure my spelling is correct the following three lines
work (note the change I had to make to the first line).

Windows("ContactInformation.xls").Activate
Worksheets("Contact").Select
Range("ContactName").Select


Subscript errors are pretty easy to find, generally. Post the code you are
using and indicate which line gives the error. Is the listbox on a userform
or on a worksheet? Where is the code - standard module, userform module,
sheet module?


--
Dick Kusleika
MVP - Excel
Daily Dose of Excel
http://www.dicks-blog.com


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
populate listbox? Alen32 Excel Programming 2 June 4th 05 01:18 PM
Using a VBA listbox to populate a worksheet Paulc Excel Programming 1 January 28th 05 01:29 PM
populate listbox JSnader Excel Programming 2 December 6th 03 02:43 PM
Populate listBox Hamster Excel Programming 1 September 17th 03 01:14 PM
ListBox Populate Rod Taylor Excel Programming 3 July 22nd 03 12:11 AM


All times are GMT +1. The time now is 04:05 PM.

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

About Us

"It's about Microsoft Excel"