.additem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have two combo boxes: cboCount1 and cboCount2.
i have a long list of same items added to the drop down list of both combo
boxes.

With cboCount1
.additem = "1"
.additem = "2"
.additem = "3"
End With

With cboCount2
.additem = "1"
.additem = "2"
.additem = "3"
End With

I need to make my codes as short and compressed as possible. I want to use
the same list for both combo boxes but use a shortcut. How can i achieve this.

thanks in advance
 
Maybe you can just do one item by item and use that list for the second
combobox.

Option Explicit
Private Sub UserForm_Initialize()
With Me.cboCount1
.AddItem "1"
.AddItem "2"
.AddItem "3"
End With
Me.cboCount2.List = Me.cboCount1.List
End Sub

Or just build one array and use it twice:

Option Explicit
Private Sub UserForm_Initialize()
Dim myArr As Variant
myArr = Array("1", "2", "3")
Me.cboCount1.List = myArr
Me.cboCount2.List = myArr
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top