If then to hide a combo box

G

Guest

I am trying to make a combo box appear if a value is greater than 1 or hide
if it is not. Below is what I have, but it does not work. Suggestions?

Private Sub test_change()
If Range("AJ19").Value > 1 Then
UserForm1.ComboBox1.Visible = True
Else
UserForm1.ComboBox1.Visible = False
End If
End Sub
 
G

Guest

I got the code to work. I only added a workseet reference.


Sub test_form()
If Worksheets("main").Range("AJ19").Value > 1 Then
UserForm1.ComboBox1.Visible = True
Else
UserForm1.ComboBox1.Visible = False
End If
UserForm1.Show

End Sub
 
G

Guest

Joel,

Thanks for the help, but I still not able to make it work. I even tried a
blank workbook and worksheet, but no change. Any idea what I am missing?
 
G

Guest

Do you know how to put break points into the code in VBA. there are two
possible reasons for problems

1) The code isn't being called. Put breakpoint in VBA code by putting
cursor on the line and pressing F9. the usual reason for this is the code
was put on the wrong module. there are different modules that are associated
with different worksheets in excel. Go to excel and right click the
worksheet tabe on the bottom of the worksheet. select view code. Put the
code on this worksheet


2) the form or combobox has a different number than the one you are calling.
right click the form and combox and select properties. The first line is
the alphabetize property box is a name. This is the name you should use when
call the form or combobox. I usually change these names to things like
Plantscombox, TreeCombobox or whatever type data you are putting into these
boxes. Otherwise, if you have multiple boxes or forms you end up referencing
the wrong items. Usually problems occur when you delete items excel skips
these numbers. You probably have combobox2 instead of combobox1.
 
G

Guest

Joel,

I appreciate your efforts, but I still missing something. You you be
willing to make up an example and email it to me or could I email my sample
to you and you look at it to see what I have going wrong? My email address
is coop458 @aol.com

Thanks Terry
 

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