add items from listbox to combo

irresistible007

Board Regular
Joined
Nov 24, 2005
Messages
173
Okay - i have give up... i tried it myself but since i am a novice.. i do always comeup with trouble... here is the scenario:

I have a list box on sheet 1 and a combo box on sheet 2. I want to add to this combo box, all current items of list box... here is the nasty code i have typed this far... but i myself can see the logical hole in it... couldn't come up wid the sol..

Private Sub ComboBox1_DropButtonClick()
ComboBox1.Clear
Dim nindex As Integer
For nindex = 0 To Sheet1.ListBox1.ListCount - 1
ComboBox1.AddItem Sheet1.ListBox1.List(Sheet1.ListBox1.ListIndex)
Next
End Sub


the above is obviously listing the 1st item only and for 3 times
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

irresistible007

Board Regular
Joined
Nov 24, 2005
Messages
173
well i found it myself.. for benefit of all here is the code:


Private Sub ComboBox1_DropButtonClick()
ComboBox1.List = Sheet1.ListBox1.List
End Sub

Previously i was mistakenly adding
Combobox1.clear before the line
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,911
Office Version
  1. 365
Platform
  1. Windows
Previously i was mistakenly adding
Combobox1.clear before the line
I don't actually think that was the problem.

Instead of this
Code:
ComboBox1.AddItem Sheet1.ListBox1.List(Sheet1.ListBox1.ListIndex)
you should probably have used this.
Code:
ComboBox1.AddItem Sheet1.ListBox1.List(nindex)
Though the code you have now is probably more efficient.
 

Watch MrExcel Video

Forum statistics

Threads
1,111,489
Messages
5,541,018
Members
410,540
Latest member
FlaShow
Top