Hide / Unhide Userform Controls

Rupert Bennett

Active Member
Joined
Nov 20, 2002
Messages
276
Hello,
Sorry if I am long winded, but I just want to state my problem clearly, so it may be easier to get a solution.
I am searching for a VBA solution for hiding and showing some userform controls based on the value in another control. There are 4 controls, among others, on the userform. There is cboIsGraded that can have a value of "Yes" or "No".
If the value in cboIsGraded is "No", I then want the txtGrade, txtGradingCo and txtGradingFee visible to be false, or true if cboIsGraded.Value is "Yes".
I have tried putting some code like:

If cboIsGraded.value = "NO" then txtGrade.visible = False. I also tried putting the code in the Change and Exit events of cboIsGraded, without any success.

Thanks in advance for your help.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi
one way maybe would be to use the Change Event of the combobox to loop over the controls you want to hide in an array

VBA Code:
Private Sub cboIsGraded_Change()
    Dim Ctrl As Variant
    For Each Ctrl In Array(txtGrade, txtGradingCo, txtGradingFee)
        Ctrl.Visible = Me.cboIsGraded.Value = "Yes"
    Next Ctrl
End Sub

Dave
 
Upvote 0
Solution
Thank you very much, Dave. This works perfectly. I guess that if I want to also hide the associated labels, I could just put them into the array. I am really happy with this. I spent a long time searching forums and trying different codes in the Change, Exit and afterUpdate events without any success. Thanks again.
 
Upvote 0
Most welcome glad suggestion helps you & appreciate your feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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