ComboBox1

G

grahammal

I have generated a ComboBox1 in a UserForm1.
I have a list of data in Sheets("DoNotUse").Range("L3", "L57").
How do I get that list into my ComboBox.

If it helps, this list is called 'grade' using 'Insert', 'Name'
'Define'.
Is a ComboBox the best thing to use or should I be using a ListBox
 
D

Dave Peterson

One way is to use:

Option Explicit
Private Sub UserForm_Initialize()
With Me.ComboBox1
.List = ThisWorkbook.Worksheets("donotuse").Range("define").Value
End With
End Sub

If the cells contained values that were nicely formatted, you could add those
nicely formatted values to the combobox:

Option Explicit
Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range

Set myRng = ThisWorkbook.Worksheets("donotuse").Range("define")

With Me.ComboBox1
For Each myCell In myRng.Cells
.AddItem myCell.Text
Next myCell
End With
End Sub
 
Top