ComboBox.visible = False or True

  • Thread starter Thread starter Charlie
  • Start date Start date
C

Charlie

This code shows updates the worksheet cell when ComboBox1 is changed. Then
it updates CombBox2 to reflect this new change.

Private Sub ComboBox1_Change()
Worksheets("sheet1").Range("C16") = Me.ComboBox1.Value
CombBox2 = Worksheets("Sheet1").Range("B23").Value
End Sub

....now if this ComboBox2 doesn't have a value, I want to combobox itself to
be visible=Fasle.
I could add another line in the above code to do this, right? I tried
adding this, but it didn't work:

If ComboBox2 .Value = "" Then
ComboBox2 .Visible = False
Else
ComboBox2 .Visible = True
End If

....am I close to getting it?
 
I couldn't get that to work: I said combobox, but meant textbox, earlier, so
let me start over:

I have ComboBox1 & TextBox1. A change is made to ComboBox1, which affects
TextBox1. If TextBox1 is blank (no string), then I need the property
..visible of TextBox1 to be set to False. I think this all happens here?

Private Sub ComboBox1_Change()
Worksheets("sheet1").Range("C16") = Me.ComboBox1.Value
TextBox1 = Worksheets("Sheet1").Range("B23").Value
If TextBox1.Value = "" Then
Me.Controls.TextBox1.Visible = False
Else
Me.Controls.Text1.Visible = True
End If
End Sub

....but the line Me.Controls.Text1.Visible gives me an error.
It must be close to being right...
 
...but the line Me.Controls.Text1.Visible gives me an error.

You use the Controls collection when you want to refer to a control by its
name. E.g.,

Me.Controls("TextBox1").Visible = False

If you are referring directly to the control, omit the Controls reference:

Me.TextBox1.Visible = False


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
I made to typing error Me.Controls.Text1
I fixed to Me.Controls.TextBox1 but it still doesn't work...
 

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

Back
Top