ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   trouble loading a range into a comboBox (https://www.excelbanter.com/excel-programming/404424-trouble-loading-range-into-combobox.html)

Janis

trouble loading a range into a comboBox
 
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,

Gary Keramidas

trouble loading a range into a comboBox
 
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.

--


Gary


"Janis" wrote in message
...
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,




Nigel[_2_]

trouble loading a range into a comboBox
 
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

--

Regards,
Nigel




"Janis" wrote in message
...
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,



merjet

trouble loading a range into a comboBox
 
Try this.

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

Hth,
Merjet


Janis

trouble loading a range into a comboBox
 
Nigel
Thanks for the answer. It really is urgent. Helped immensely. :)

"Nigel" wrote:

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

--

Regards,
Nigel




"Janis" wrote in message
...
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,



Dave Peterson

trouble loading a range into a comboBox
 
Check your first post, too.

Janis wrote:

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,


--

Dave Peterson


All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com