Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to hide option button on Userform if the caption has no text

I have 4 option buttons and their caption is set to different cells. However, sometimes that cell value doesn’t contain any text, and I want to hide the option button from the Userform if that is the case. But my code is hiding the option buttons even if the caption contains text. I’m sure this is simple, but I can’t solve it.

Call ifBlank

OptionButton1.Caption = qRange1.Value
OptionButton2.Caption = qRange2.Value
OptionButton3.Caption = qRange3.Value
OptionButton4.Caption = qRange4.Value

Sub ifBlank()


If OptionButton3.Caption = "" Then

    OptionButton3.Visible = False

If OptionButton4.Caption = "" Then

    OptionButton4.Visible = False
    
End If
End If

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a) Call ifBlank after setting the captions, not before.

b) You can simply write

Sub ifBlank()
    OptionButton1.Visible = (OptionButton1.Caption <> "")
    OptionButton2.Visible = (OptionButton2.Caption <> "")
    OptionButton3.Visible = (OptionButton3.Caption <> "")
    OptionButton4.Visible = (OptionButton4.Caption <> "")
End If
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading