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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XL97 Populate Combobox from range in excel VBA 1

Status
Not open for further replies.

vaneagle

Technical User
Apr 23, 2003
71
AU
Hi,

Is there a way in excel 97 where I have data in say sheet1 range A1:A10, and I then use that data to populate my combobox using VBA?

Code:
Private Sub UserForm_Initialize()

'what do i put here!!!

End Sub

 
You can either use the AddItem method or the listfillrange property

Combobox1.listfillrange = "A1:A10"

Or

For 1 = 1 to 10
Combobox1.additem sheets("Sheet1").cells(i,1).text
next i

I don't mean to be rude but this is a very basic question that can be answered easily by using either the VBA help files or the object model

just type "combobox" into the answer wizard or in the VBE, press F2 to bring up the object model and enter combobox into the search engine - you get a complete list of all methods and properties in there - all with a link to their "help" pages

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Thanks Geoff...

The second option worked.

I am new to using forms with vba and I spent several hours yesterday trying to get something to work. The listfillrange property method never worked and it always errored on me. I did look in help but due to my lack of knowledge with forms let alone VBA, I decided to post the question. I had initially hardcoded the add items:

Code:
.AddItem "01 - Jan 04"
.AddItem "01 - Feb 04"
etc...

but I needed an easier way for the end user to change for the following year..without going into VBA and changing the code...Hence loading data from a sheet in excel.

Apologies for asking a simple question...

Have a star as your second suggestion worked. Thankyou.
 
Please don't apologise for asking a "simple" question.I mentioned the help files and object model as I thought it might help out if you have another, similar issue. I hope you were not offended as no offense was meant.

The listfillrange probably needs a Sheet as well so
Listfillrange = "Sheet1!A1:A10"
should work for future reference

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top