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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top