Userform combo box

G

Guest

Hi,

Due to some superb help from these groups I have almost achieved what I
wanted to do using a userform, I have one last hurdle now that involves using
a combo box on a userform.

Do these follow the rules of normal of combo boxes in regards to a cell link
and input range? If so could I have some pointers please on how to set up the
properties?

Thank you very much
Andy
 
G

Guest

I depends on what you think the normal rules are.

right click on the combobox and select properties. in rowsource, the link
for the dropdown list, put something like

Sheet1!A1:A30

in Control source (the link for the result)
sheet2!B9
 
G

Guest

Thank you Tom!

Thats perfect


Thanks

Tom Ogilvy said:
I depends on what you think the normal rules are.

right click on the combobox and select properties. in rowsource, the link
for the dropdown list, put something like

Sheet1!A1:A30

in Control source (the link for the result)
sheet2!B9
 
S

Souny

Tom,

Could you help me one thing?

I have a combo box in one of my worksheets, and the code for the combo box
is also in the same worksheet "Sheet1". Basically, the code will execute the
lines based on the value selected (from clicking) from the combo box.
Somehow, the code automatically executes when the file is opened.

I have tried many ways, and I am still having problems. I don't understand
why the code will automatically execute when the file is opened.

Below is my code structure.

Private Sub cboCode_Click()

Application.ScreenUpdating=False

Select Case cboCode.Value
Case "Selection1"
'Do the following
Case "Selection2"
'Do the following
Cash "Selection3"
'Do the following
Case Else
'Do the following
End Select

Application.ScreenUpdating = True
End Sub

Please help.

Thanks.
 
B

Bernie Deitrick

Souny,

Try using the Change event rather than the click event. The initial recalc seems to be firing the
click event code, but should not fire the change event.

HTH,
Bernie
MS Excel MVP
 
S

Souny

Bernie,

Thanks for your response. I tried with Change event, and the problem still
exists.

I don't know why. Please help.
 
B

Bernie Deitrick

Does the combobox list range contain formulas rather than values?

At the end of it all, you could change your macro code to look at some other enabling value that you
store in a named cell somewhere... for example

If Range("DisableCombo").Value <> "Enabled" Then Exit Sub

HTH,
Bernie
MS Excel MVP
 
S

Souny

Bernie,

Thank you very much for continuing to help.

The values in the combo box are looking up the cells $C$1:$C$4 in Sheet1,
and the cells are referenced in ListFillRange as $C$1:$C$4 in the combo box
Properties. Therefore, the values are not populated from the code.

Do you think I need to add your code as part of my code like the following?

If Range("$C$1:$C$4").Value <> "Enabled" Then Exit Sub

Please help. Thanks.
 
B

Bernie Deitrick

Souny,

I was not able to replicate your problem, with my setup.

Are there formulas in C1:C4 or are they values?

And if you want, you can send the workbook to me privately. Just make the obvious changes to my
email address.

HTH,
Bernie
MS Excel MVP
 
S

Souny

Bernie,

I would love to send you my workbook; however, I can't due to the company's
policy. Please help me without my workbook.

Besides my workbook, I did a test workbook. In the test workbook, I create
a combo box in Sheet1, and in cells $C$1:$C$4 of Sheet1, I type in the
values. The values in cells $C$1:$C$4 of both actual and test workbooks are
values, not formula. Then I have $C$1:$C$4 in ListFillRange and combo box
name cboTest in Name of combo box Properties, and I change nothing else in
the combo box Properties.

In the VBAProject of Sheet1, I have the following code:

private sub cboTest_Click()
application.screenupdating=false
select case cboTest.value
case "Selection1"
msgbox "selection1"
case "selection2"
msgbox "selection2"
case "selection3"
msgbox "selection3"

end select
application.screenupdating=true
end sub

I click on the combo box to change the value, and it works. When I close
the workbook and reopen it, the combo box code executes. For example, when I
open the workbook with "selection3" in my combo box, I would receive a
message "selection3".

Did I miss something? Is there a setting in Excel (e.g. Tools > Options)
that I need to check to say do not execute the combo box code when the file
is opened?

Thanks.
 
B

Bernie Deitrick

Souny,

I did exactly that before, and again just now, and I do not replicate your problem.

Try starting Excel in safe mode. See

http://www.cpearson.com/excel/StartupErrors.aspx

for instructions on how.

Also, I am running Excel 2003 - what version and operating system are you using?
Do you have any event code in your default workbook's Thisworkbook's codemodule?

HTH,
Bernie
MS Excel MVP
 
D

Dave Peterson

You may want to just bite the bullet and drop the linkedcell and rowsource and
replace them with code.
 
S

Souny

Bernie,

I am using Excel 2003 Standard and Windows XP Professional. I don't have
anything in the ThisWorkbook.

What is it supposed to happen if I open my workbook in safemode?

Thanks.
 
D

Dave Peterson

Say you have the list in a range on a separate sheet named "ListInfo" in A1:A10.
And you want the linked cell on the same worksheet as the combobox in A1.

And you want to populate the combobox when the workbook opens.

My combobox was named combobox1 and is on Sheet1.

I had this code in a General module:

Option Explicit
Sub Auto_Open()
Dim wks As Worksheet
Dim ListRng As Range

Set wks = Worksheets("Sheet1")

With Worksheets("ListInfo")
Set ListRng = .Range("A1:A5")
End With

wks.OLEObjects("combobox1").Object.List = ListRng.Value
End Sub

Behind the worksheet with the combobox:
Option Explicit
Private Sub ComboBox1_Change()
Me.Range("A1").Value = Me.ComboBox1.Value
End Sub

========
I have no idea how often that combobox needs to have its list refreshed. Maybe
using a different event would make more sense.
 
S

Souny

Dave,

Thank you very much for the code. I will try it and let you know.

One thing that does not make sense to me. Why do we have to go through the
code to populate the values, and why my setup would not work?

I thought the intend of the combo box is to execute the code when we click
on the combo box and when the value changes in the combo box, not to execute
automatically when the file opens. Am I correct?

Did I miss something during the setup that you can think of?

Thanks again.
 
D

Dave Peterson

Somethings cause xl to recalculate and think that that linked cell (or list)
changed (I'm not sure which one).

I'm not sure what they are or when they do it (what version of excel are you
using?).

Just a couple of days ago, there was another user who had the same problem. I
couldn't duplicate it xl2003 (which is what they were using, too(!)).

All I know is that sometimes it's just easier to use code than to struggle.
Dave,

Thank you very much for the code. I will try it and let you know.

One thing that does not make sense to me. Why do we have to go through the
code to populate the values, and why my setup would not work?

I thought the intend of the combo box is to execute the code when we click
on the combo box and when the value changes in the combo box, not to execute
automatically when the file opens. Am I correct?

Did I miss something during the setup that you can think of?

Thanks again.
 
S

Souny

Dave,

Thanks for the explanation. I am using Excel 2003 Standard and Windows XP
Profession.

Have a great weekend.

By the way, thanks for your helps on the message "Need Help on Define Names"
that I posted on 09/19/09. I apologize for not able to respond to your
message.
 
D

Dave Peterson

Hope it works for you.
Dave,

Thanks for the explanation. I am using Excel 2003 Standard and Windows XP
Profession.

Have a great weekend.

By the way, thanks for your helps on the message "Need Help on Define Names"
that I posted on 09/19/09. I apologize for not able to respond to your
message.
 
S

Souny

Dave,

I have a quick question. What is the purpose of using the "Option
Explicit"? Thanks.
 

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