#1   Report Post  
Jeff
 
Posts: n/a
Default VBA Combo Box

I have a combo box that I want to populate with a list of names.

I do not want to reference names in the worksheet - using "RowSource" - I
want to write the names in the code.

I tried the following code:

Private Sub ComboBox1_Change()
With ComboBox1
..RowSource = ""
..AddItem "Male"
..AddItem = "Female"
End With
End Sub

This gives me an error. Does anyone know where the code should be added.

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Is this on a userform?

If yes, then maybe it should be in the Userform_initialize procedure?

If it's on a worksheet, maybe in the auto_open or workbook_open procedures.

Jeff wrote:

I have a combo box that I want to populate with a list of names.

I do not want to reference names in the worksheet - using "RowSource" - I
want to write the names in the code.

I tried the following code:

Private Sub ComboBox1_Change()
With ComboBox1
.RowSource = ""
.AddItem "Male"
.AddItem = "Female"
End With
End Sub

This gives me an error. Does anyone know where the code should be added.


--

Dave Peterson
  #3   Report Post  
Jeff
 
Posts: n/a
Default



"Dave Peterson" wrote:

It is in a form

Private Sub UserForm_Initialize()
With ComboBox1
..RowSource = ""
..AddItem "Male"
..AddItem = "Female"
End With
End Sub

Gives an error. Is this what you meant by "Userform_Initialize" procedure
  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Yep.

And I didn't notice your typo in the original post:

.AddItem = "Female"
should be:
.AddItem "Female"

(no equal sign)

Jeff wrote:

"Dave Peterson" wrote:

It is in a form

Private Sub UserForm_Initialize()
With ComboBox1
.RowSource = ""
.AddItem "Male"
.AddItem = "Female"
End With
End Sub

Gives an error. Is this what you meant by "Userform_Initialize" procedure


--

Dave Peterson
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
Nesting Combo Boxes /Returning an Array ELMONDO SNITHER Excel Discussion (Misc queries) 1 June 30th 05 01:15 AM
Dynamic Combo Box benjarfer Excel Worksheet Functions 2 April 8th 05 02:17 PM
connecting combo boxes to yield data in another cell. TxN8tv Excel Discussion (Misc queries) 0 March 14th 05 04:07 PM
"Combo Box - getting control combo box to stick in place in worksh ajr Excel Discussion (Misc queries) 1 February 16th 05 02:05 AM
dynamic combo boxes tjb Excel Worksheet Functions 2 January 25th 05 07:33 PM


All times are GMT +1. The time now is 11:52 AM.

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"