ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Form Help - ComboBox - VBA (https://www.excelbanter.com/excel-discussion-misc-queries/216332-form-help-combobox-vba.html)

jlclyde

Form Help - ComboBox - VBA
 
I have a form and when I initialize the form I need multiple combo
boxes to fill in with the same data. Is there an easier way then
doing .additem for each one? My code below.

Thanks Jay

Private Sub UserForm_Initialize()


With CmbxFirst 'this loads the combo
.AddItem "LDC"
.AddItem "DC"
.AddItem "DB"
.AddItem "LDDB"
.AddItem "XmasDB"
.AddItem "XmasLDDB"
.AddItem "XmasDC"
.AddItem "XmasLDC"
.AddItem "No Die"
.AddItem "Same Die As"
End With
With CmbxSecond 'this loads the combo
.AddItem "LDC"
.AddItem "DC"
.AddItem "DB"
.AddItem "LDDB"
.AddItem "XmasDB"
.AddItem "XmasLDDB"
.AddItem "XmasDC"
.AddItem "XmasLDC"
.AddItem "No Die"
.AddItem "Same Die As"
End With

Jim Cone[_2_]

Form Help - ComboBox - VBA
 

Private Sub UserForm_Initialize()
Dim varList As Variant
varList = Array("LDC", "DC", "DB", "LDDB", "XmasDB", "XmasLDDB", _
"XmasDC", "XmasLDC", "No Die", "Same Die As")
CmbxFirst.List = varList
CmbxSecond.List = varList
End Sub
--
Jim Cone
Portland, Oregon USA


"jlclyde"

wrote in message
I have a form and when I initialize the form I need multiple combo
boxes to fill in with the same data. Is there an easier way then
doing .additem for each one? My code below.
Thanks Jay

Private Sub UserForm_Initialize()
With CmbxFirst 'this loads the combo
.AddItem "LDC"
.AddItem "DC"
.AddItem "DB"
.AddItem "LDDB"
.AddItem "XmasDB"
.AddItem "XmasLDDB"
.AddItem "XmasDC"
.AddItem "XmasLDC"
.AddItem "No Die"
.AddItem "Same Die As"
End With
With CmbxSecond 'this loads the combo
.AddItem "LDC"
.AddItem "DC"
.AddItem "DB"
.AddItem "LDDB"
.AddItem "XmasDB"
.AddItem "XmasLDDB"
.AddItem "XmasDC"
.AddItem "XmasLDC"
.AddItem "No Die"
.AddItem "Same Die As"
End With

Mike H

Form Help - ComboBox - VBA
 
Hi,

To make the list easily maintainable I'd store them on a worksheet (in this
case sheet4) and load them like this

Private Sub UserForm_Activate()
Dim rng As Range
Dim arr As Variant
Set SH = Sheets("Sheet4")
Set rng = SH.Range("A1:A10")
arr = rng.Value
Me.CmbxFirst.List = arr
End Sub

Mike

"jlclyde" wrote:

I have a form and when I initialize the form I need multiple combo
boxes to fill in with the same data. Is there an easier way then
doing .additem for each one? My code below.

Thanks Jay

Private Sub UserForm_Initialize()


With CmbxFirst 'this loads the combo
.AddItem "LDC"
.AddItem "DC"
.AddItem "DB"
.AddItem "LDDB"
.AddItem "XmasDB"
.AddItem "XmasLDDB"
.AddItem "XmasDC"
.AddItem "XmasLDC"
.AddItem "No Die"
.AddItem "Same Die As"
End With
With CmbxSecond 'this loads the combo
.AddItem "LDC"
.AddItem "DC"
.AddItem "DB"
.AddItem "LDDB"
.AddItem "XmasDB"
.AddItem "XmasLDDB"
.AddItem "XmasDC"
.AddItem "XmasLDC"
.AddItem "No Die"
.AddItem "Same Die As"
End With


jlclyde

Form Help - ComboBox - VBA
 
On Jan 13, 1:11*pm, "Jim Cone" wrote:
Private Sub UserForm_Initialize()
* Dim varList As Variant
* varList = Array("LDC", "DC", "DB", "LDDB", "XmasDB", "XmasLDDB", _
* * * * * * * * * * * * * * "XmasDC", "XmasLDC", "No Die", "Same Die As")
* CmbxFirst.List = varList
* CmbxSecond.List = varList
End Sub
--
Jim Cone
Portland, Oregon *USA

"jlclyde"

wrote in message
I have a form and when I initialize the form I need multiple combo
boxes to fill in with the same data. *Is there an easier way then
doing .additem for each one? *My code below.
Thanks Jay

Private Sub UserForm_Initialize()
With CmbxFirst 'this loads the combo
* * .AddItem "LDC"
* * .AddItem "DC"
* * .AddItem "DB"
* * .AddItem "LDDB"
* * .AddItem "XmasDB"
* * .AddItem "XmasLDDB"
* * .AddItem "XmasDC"
* * .AddItem "XmasLDC"
* * .AddItem "No Die"
* * .AddItem "Same Die As"
End With
With CmbxSecond 'this loads the combo
* * .AddItem "LDC"
* * .AddItem "DC"
* * .AddItem "DB"
* * .AddItem "LDDB"
* * .AddItem "XmasDB"
* * .AddItem "XmasLDDB"
* * .AddItem "XmasDC"
* * .AddItem "XmasLDC"
* * .AddItem "No Die"
* * .AddItem "Same Die As"
End With


Jim,

jlclyde

Form Help - ComboBox - VBA
 
On Jan 13, 1:11*pm, "Jim Cone" wrote:
Private Sub UserForm_Initialize()
* Dim varList As Variant
* varList = Array("LDC", "DC", "DB", "LDDB", "XmasDB", "XmasLDDB", _
* * * * * * * * * * * * * * "XmasDC", "XmasLDC", "No Die", "Same Die As")
* CmbxFirst.List = varList
* CmbxSecond.List = varList
End Sub
--
Jim Cone
Portland, Oregon *USA

"jlclyde"

wrote in message
I have a form and when I initialize the form I need multiple combo
boxes to fill in with the same data. *Is there an easier way then
doing .additem for each one? *My code below.
Thanks Jay

Private Sub UserForm_Initialize()
With CmbxFirst 'this loads the combo
* * .AddItem "LDC"
* * .AddItem "DC"
* * .AddItem "DB"
* * .AddItem "LDDB"
* * .AddItem "XmasDB"
* * .AddItem "XmasLDDB"
* * .AddItem "XmasDC"
* * .AddItem "XmasLDC"
* * .AddItem "No Die"
* * .AddItem "Same Die As"
End With
With CmbxSecond 'this loads the combo
* * .AddItem "LDC"
* * .AddItem "DC"
* * .AddItem "DB"
* * .AddItem "LDDB"
* * .AddItem "XmasDB"
* * .AddItem "XmasLDDB"
* * .AddItem "XmasDC"
* * .AddItem "XmasLDC"
* * .AddItem "No Die"
* * .AddItem "Same Die As"
End With


Jim,
You are a genious. This works awesome. thanks for the help.
Jay

Jim Cone[_2_]

Form Help - ComboBox - VBA
 
You are welcome.
--
Jim Cone
Portland, Oregon USA



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

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