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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

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
76,304
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.
 

Forum statistics

Threads
1,141,740
Messages
5,708,229
Members
421,553
Latest member
Geeyj

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
Top