![]() |
|
#1
|
|||
|
|||
|
Hello,
I try to fill a combobox with Text from an excelsheet. The code i wrote works fine, but when i select my combobox a second time, then the entries will appear a second time in my combobox and after clicking a third time on the arrow to open it, all entries are three times there and so on. I am not using an userform, i have inserted the an activeX element for combobox in the excel sheet from Developer tools. Here is the code: Private Sub ComboBox2_Change() Dim WS As Worksheet Dim LastRow As Long Dim aCell As Range Dim lIndxA As Long Dim lIndxI As Long Dim sTemp As String ComboBox2.Clear Call FillCombobox("List", "B", Me.ComboBox2) Set WS = ActiveWorkbook.Worksheets("List") With WS LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row For Each aCell In .Range("B2:B500" & LastRow) If aCell.Value <> "" Then Me.ComboBox2.AddItem aCell.Value End If Next For lIndxA = 0 To Me.ComboBox2.ListCount - 1 For lIndxI = 0 To lIndxA - 1 If Me.ComboBox2.List(lIndxI) > Me.ComboBox2.List(lIndxA) Then sTemp = Me.ComboBox2.List(lIndxI) Me.ComboBox2.List(lIndxI) = Me.ComboBox2.List(lIndxA) Me.ComboBox2.List(lIndxA) = sTemp End If Next lIndxI Next lIndxA End With End Sub I hope someone can help me. regards |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Using combobox to pass data from an Excel spread sheet to text boxes on userform
|
Stewie840 | Word VBA | 14 | 12-17-2015 10:13 PM |
combobox list gets reset....please help
|
Deepa Shrestha | Word VBA | 1 | 09-29-2013 09:30 PM |
VB code: populate combobox from columns in Excel file
|
billybeach | Outlook | 2 | 04-27-2013 04:38 AM |
Adding a long list of values to a combobox in Word 2003?
|
ll4u76 | Word VBA | 1 | 04-13-2012 03:37 AM |
Populating ComboBox or Drop Down list with contents of a text field
|
Billy_McSkintos | Word VBA | 1 | 09-13-2011 05:50 AM |