Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a listbox with cell data when file is opened.

Status
Not open for further replies.

bujin

MIS
Oct 2, 2000
144
GB
I have an Excel worksheet ("RLD") containing a combobox which I want to populate with a range of values in a second worksheet ("DATA"). I have the code to do this, as follows:

RLD.lstSubject.Clear
For i = 2 To c - 1
RLD.lstSubject.AddItem Worksheets("DATA").Cells(i, 1).Value
Next i

Here, RLD is the name of the main worksheet and lstSubject is the list I want to populate. c is the value of the first row that does not contain data, i.e. the end of the list.

This works fine, but I have to manually populate it when the worksheet is loaded. How can I get Excel to populate the values automatically when the workbook is opened?

I've tried the above function in the Workbook_Open sub, but it doesn't seem to work.

Anybody? :)
 
It looks like you need to change it to.

Worksheets("RLD").lstSubject.Clear
For i = 2 To c - 1
Worksheets("RLD").lstSubject.AddItem Worksheets("DATA").Cells(i, 1).Value
Next i
 
D'oh!!!

Someone give me an electronic slapping! I missed out a rather important piece of code that actually calculates the value of 'c' in the first place!!!
 
Zap Slap !

:)

are you all set ?

if you need help email me

drat@mediaone.net

Ratman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top