ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Same Items in 3 different Combo Boxes (https://www.excelbanter.com/excel-programming/406759-same-items-3-different-combo-boxes.html)

RyanH

Same Items in 3 different Combo Boxes
 
I have three Combo Boxes in a UserForm that I need to display all 50 state
initials. I usually write my code like this:

Private Sub UserForm_Initialize()

With cboCustomerST
.AddItem "GA"
.AddItem "TN"
.AddItem "NY"
'list all other state
End With

End Sub

Is there a faster way to do this with 2 other combo boxes instead writing
code for each combo box?

Thanks in Advance,
Ryan

PaulW

Same Items in 3 different Combo Boxes
 
for i = 1 to 3
userform1.controls("ComboBox" & i).additem "GA"
next i

Thats what I usually do.

"RyanH" wrote:

I have three Combo Boxes in a UserForm that I need to display all 50 state
initials. I usually write my code like this:

Private Sub UserForm_Initialize()

With cboCustomerST
.AddItem "GA"
.AddItem "TN"
.AddItem "NY"
'list all other state
End With

End Sub

Is there a faster way to do this with 2 other combo boxes instead writing
code for each combo box?

Thanks in Advance,
Ryan


Jim Cone

Same Items in 3 different Combo Boxes
 

Another way...
Me.ComboBox2.List = Me.ComboBox1.List
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"RyanH" <
wrote in message
I have three Combo Boxes in a UserForm that I need to display all 50 state
initials. I usually write my code like this:

Private Sub UserForm_Initialize()
With cboCustomerST
.AddItem "GA"
.AddItem "TN"
.AddItem "NY"
'list all other state
End With
End Sub

Is there a faster way to do this with 2 other combo boxes instead writing
code for each combo box?
Thanks in Advance,
Ryan

Rick Rothstein \(MVP - VB\)[_1353_]

Same Items in 3 different Combo Boxes
 
You could do it this way...

Dim S As Variant
For Each S In Split("AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA " & _
"KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ " & _
"NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT " & _
"VA WA WV WI WY")
ListBox1.AddItem S
ListBox2.AddItem S
ListBox3.AddItem S
Next

Rick


"RyanH" wrote in message
...
I have three Combo Boxes in a UserForm that I need to display all 50 state
initials. I usually write my code like this:

Private Sub UserForm_Initialize()

With cboCustomerST
.AddItem "GA"
.AddItem "TN"
.AddItem "NY"
'list all other state
End With

End Sub

Is there a faster way to do this with 2 other combo boxes instead writing
code for each combo box?

Thanks in Advance,
Ryan




All times are GMT +1. The time now is 11:16 PM.

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