Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Userform checkbox in VBA for Excel?
I created a userform in VBA that has checkboxes and textboxes. I want the user to only see the textbox in the userform when he/she checks the checkbox. For example, Label 1 asks "Do you want to buy the stock?" Next to Label 1 is checkbox 1. Then there is Label 2 that says "Stock Price", then textbox 1, where the user enters the stock price. What is the code for controlling label 2 and textbox 1 with checkbox 1; that is, I want label 2 and textbox 1 hidden until the user checks checkbox 1.
One way around this is obviously creating a userform for every option the user can choose, but i would like eight options, and therefore eight checkboxes controlling eight labels and textboxes, on one userform.
2 Answers
- Anonymous1 decade agoFavorite Answer
I used to do a simple technique in this case
1- Create a frame for each set of controls (Textbox1, label1), etc
2- Hide them all in design time
3- Add a sub with
Sub ShowHide()
Frame1.visible = false
Frame2.visible = false
Frame3.visible = false
if checkbox1.value the Frame1.visible = true
if checkbox2.value the Frame2.visible = true
if checkbox3.value the Frame3.visible = true
End Sub
add this line into each CheckBox1_Change() event
ShowHide
And you are done
I do it all the time in all of my Excel-Based applications
Check my site here to see them
http://www.projects.file1.net/
Trust me, I am the VBAXLMan
- Anonymous1 decade ago
Hi,
You the Visible option on the form control box, e.g set the visible to true if the text box is ticked.