ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If then to hide a combo box (https://www.excelbanter.com/excel-programming/384693-if-then-hide-combo-box.html)

TDC

If then to hide a combo box
 
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

joel

If then to hide a combo box
 
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




"TDC" wrote:

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


TDC

If then to hide a combo box
 
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?

"Joel" wrote:

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




"TDC" wrote:

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


joel

If then to hide a combo box
 
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.

"TDC" wrote:

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?

"Joel" wrote:

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




"TDC" wrote:

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


TDC

If then to hide a combo box
 
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

"Joel" wrote:

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.

"TDC" wrote:

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?

"Joel" wrote:

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




"TDC" wrote:

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



All times are GMT +1. The time now is 10:42 PM.

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