Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2015, 04:46 AM
VBA-User VBA-User is offline Excel Combobox List Windows 7 64bit Excel Combobox List Office 2013
Novice
Excel Combobox List
 
Join Date: Dec 2015
Posts: 5
VBA-User is on a distinguished road
Default Excel Combobox List

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
Reply With Quote
  #2  
Old 12-21-2015, 07:20 AM
NoSparks NoSparks is offline Excel Combobox List Windows 7 64bit Excel Combobox List Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Think you should post a sample workbook.
Reply With Quote
  #3  
Old 01-05-2016, 10:32 AM
VBA-User VBA-User is offline Excel Combobox List Windows 7 64bit Excel Combobox List Office 2013
Novice
Excel Combobox List
 
Join Date: Dec 2015
Posts: 5
VBA-User is on a distinguished road
Default

ok here is an example file. Sorry its a bit late, i tried so solve the problem by myself ... couldnt find a solution. Every entry will be copied in the combobox after clicking on the arrow for opening. I get each entry many times.

http://www.file-upload.net/download-...mple.xlsm.html
Reply With Quote
  #4  
Old 01-06-2016, 02:45 PM
NoSparks NoSparks is offline Excel Combobox List Windows 7 64bit Excel Combobox List Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

I'm not sure I follow what you're doing, and definitely don't follow when it's being done.
Using the _Change() event will fire the FillCombobox procedure every time any character is typed into the combo box.
I'd think you would want the drop downs to populate before entering anything.
Perhaps using the _GotFocus event instead of _Change.
Code:
Private Sub ComboBox1_GotFocus()
    Call FillCombobox("List", "A", Me.ComboBox1)
End Sub
and like this for the FillCombobox procedure
Code:
Sub FillCombobox(WSName As String, ColLtr As String, CBox As ComboBox)
    Dim LastRow As Long
Set ws = ActiveWorkbook.Worksheets("List")
With ws
    LastRow = .Cells(.Rows.Count, ColLtr).End(xlUp).Row
    CBox.List = .Range(ColLtr & "3:" & ColLtr & LastRow).Value
End With
End Sub
Reply With Quote
  #5  
Old 01-07-2016, 02:46 AM
VBA-User VBA-User is offline Excel Combobox List Windows 7 64bit Excel Combobox List Office 2013
Novice
Excel Combobox List
 
Join Date: Dec 2015
Posts: 5
VBA-User is on a distinguished road
Default

I will try it, thank you.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Combobox List 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
Excel Combobox List combobox list gets reset....please help Deepa Shrestha Word VBA 1 09-29-2013 09:30 PM
Excel Combobox List VB code: populate combobox from columns in Excel file billybeach Outlook 2 04-27-2013 04:38 AM
Excel Combobox List Adding a long list of values to a combobox in Word 2003? ll4u76 Word VBA 1 04-13-2012 03:37 AM
Excel Combobox List Populating ComboBox or Drop Down list with contents of a text field Billy_McSkintos Word VBA 1 09-13-2011 05:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft