Userform Combobox

Nine Zero

Well-known Member
Joined
Mar 10, 2016
Messages
625
Hello All,

I have a userform with a combobox that on Initialize the combobox is loaded with about 23000+ items

I have a checkbox where it will remove all of them currently 1 by 1 and load another list of only about 200 items

When the checkbox is unchecked it will reverse it by removing the 200 1 by 1 then re-adding the original list again and vice versa

There is currently a 6 second lag to load any of the lists into the combobox which i fully understand due to the removing and re-adding

is there a "faster" way to clear a combobox other than removing 1 by 1 each item?

Thank you
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Ok so i just used the .Clear function and it sped it up to only about 1 second lag 1 way but the other way lags a bit more than before....weird
 
Upvote 0
below are my 3 subs for loading and removing from the box and lastly the fourth is the checkbox

Also on Initialize ... LoadCustomers is called

Code:
Sub LoadCustomers()
Dim r As Range
Dim lastc As Integer
    With Sheets("CUSTOMER_LIST")
    lastc = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
    End With
    For Each r In Sheets("CUSTOMER_LIST").Range("A2:A" & lastc)
    customernumberbox.AddItem r.Value
Next r
End Sub

Sub LoadNational()
Dim r As Range
Dim lastc As Integer
    With Sheets("NATIONAL_LIST")
    lastc = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
    End With
    For Each r In Sheets("NATIONAL_LIST").Range("A1:A" & lastc)
    customernumberbox.AddItem r.Value
Next r
End Sub

Sub RemoveCustomers()
'For i = customernumberbox.ListCount - 1 To 0 Step -1
'customernumberbox.RemoveItem i
'Next i
customernumberbox.Clear
End Sub

Private Sub nationalaccount_Click()
If nationalaccount.Value = True Then
RemoveCustomers
LoadNational
Else
RemoveCustomers
LoadCustomers
End If
End Sub
 
Last edited:
Upvote 0
I always load comboboxes like this:
Code:
Private Sub UserForm_Initialize()
Dim lastc As Integer
lastc = Sheets("CUSTOMER_LIST").Cells(Rows.Count, "A").End(xlUp).Row
customernumberbox.List = Sheets("CUSTOMER_LIST").Range("A2:A" & lastc).Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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