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
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Takae

Well-known Member
Joined
Jul 1, 2015
Messages
723
There is not the problem with your code. I have tested with over 10,000 test data.
 

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,814
Office Version
  1. 2016
  2. 2010
  3. 2007
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,126,923
Messages
5,621,621
Members
415,848
Latest member
LCC

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