Populate Combo Box from a Range - timing out

gr8trthanu

Board Regular
Joined
Nov 14, 2008
Messages
103
Hello,
I am trying to auto populate a combobox called "cmbID" from a range of cells but all I get is the running circle/times out.

The combo box is on a multipage object entitled "mtp1" which is located on a userform entitled "frmSchedule".

The information I am trying to autopopulate is from a list range entitled "PatientID" from an excel tab entitled "Patient Information"

When the userform loads I would like the combobox to autopopulate with the data from the list entitled "PatientID" which is in column A of the tab "Patient Information"

Unfortunately, I get the spinning time circle when the form is opened as VBA is trying to process the code. (I guess)

Is the range perhaps too big.

Here is the code I am using:

CODE:
***************************************************************************
Private Sub UserForm_Initialize()
'Populate combo box.
Dim rng As Range
Dim ws As Worksheet
Set ws = Worksheets("Patient Information")
For Each rng In ws.Range("PatientID")
Me.cmbID.AddItem rng
Next rng
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
There is not the problem with your code. I have tested with over 10,000 test data.
 
Upvote 0
This is much faster alternative:
Rich (BB code):
Private Sub UserForm_Initialize()
  'Populate combo box.
  With Worksheets("Patient Information")
    Me.cmbID.List = Intersect(.UsedRange, .Range("PatientID")).Value
  End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,388
Members
448,957
Latest member
Hat4Life

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