trouble loading a range into a comboBox

J

Janis

Can you tell me why when I run this userform that it erases the values in the
range A1:A12?
The userform initialize procedure runs but it erases the values in the cells
A1:A12 and it doens't have the list in the comboBox but other than that it
runs.

Private Sub UserForm_Initialize()

ThisWorkbook.Worksheets("patients").Range("A1:A12") = Me.ComboBox2.Value

End Sub

And I ran it several times and get the same results.

What am I missing?
tnx,
 
G

Gary Keramidas

your telling excel to set the range A1:a12 = to the form's combobox value. if
the combobox is empty, range("A1:A12") will be empty.
 
N

Nigel

You are currently forcing an empty ComboBox value into A1:A12, even if you
reversed the assignment it would still not load the ComboBox......use the
following to achieve that.

Dim c As Range
ComboBox1.Clear
For Each c In Worksheets("patients").Range("A1:A12")
ComboBox1.AddItem c.Value
Next c
 
M

merjet

Try this.

Private Sub UserForm_Initialize()
ComboBox2.RowSource= "patients!A1:A12"
End Sub

Hth,
Merjet
 
D

Dave Peterson

Check your first post, too.
Can you tell me why when I run this userform that it erases the values in the
range A1:A12?
The userform initialize procedure runs but it erases the values in the cells
A1:A12 and it doens't have the list in the comboBox but other than that it
runs.

Private Sub UserForm_Initialize()

ThisWorkbook.Worksheets("patients").Range("A1:A12") = Me.ComboBox2.Value

End Sub

And I ran it several times and get the same results.

What am I missing?
tnx,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top