If combobox answer is no, show a new text field

johnselekta

New Member
Joined
Jun 14, 2011
Messages
6
Hey guys and girls, I've learned lots from Mr Excel thus far, so thank you! I'm doing great building a VBA form to record in a worksheet, but I just hit a wall, so could really use some help! OK..here goes.

I have a combobox and answers can only be Yes or No.

If the answer is No, I need a new input box to appear alongside to specify why this question was answered as 'No'. It should only be shown if this condition is met.

How would I achieve this? Its the only thing preventing me from completion of my first project! :oops:

Thanks in advance!

(Made in Excel 2007 on Windows 7)
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Welcome to the board John.

You just have to change the Visible Property of the Textbox and Label based on state in the combobox. The following code will hide the text box initially and if the combobox is not "No", unhide if "No".

Code:
Private Sub UserForm_Initialize()
    TextBox1.Visible = False
    Label1.Visible = False
    ComboBox1.AddItem "Yes"
    ComboBox1.AddItem "No"
End Sub

Private Sub ComboBox1_Change()
    If ComboBox1.Text = "No" Then
        Label1.Visible = True
        TextBox1.Visible = True
    Else
        TextBox1.Visible = False
        Label1.Visible = False
    End If
End Sub
 
Upvote 0
Wow Rob this is brilliant thanks! Exactly what I was after, and quickly too! :pray:

My yes and no answers are linking from a named range in a another sheet. I'll definitely get rid of this in favour of your much cleaner method of adding

ComboBox1.AddItem "Yes"
ComboBox1.AddItem "No"

to the combobox code. Correct me if I'm wrong, but that was very clear so I'm confident this will work just fine.

Once again thanks very much, I think I'll be in a position to help answer questions myself soon at this rate!

Will implement then mark as solved - I really appreciate the help, thanks!
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top