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

Can we click multiple times on a specific label we have created and change the label text each time we click (in user form of excel VBA)?

I have a user form in excel written in VBA. There is a label in my user form and I want to change this label’s caption each time I click on it. For example: This label currently have "1" caption, for first time I click on this label, I want to change the label’s caption to "X", for the second time I click on the label, to change the label’s caption to "?", and If I click one more time, I want to change to first caption which was "1". I prefer using labels in this scenario, and Unfortunately other options like ComboBox or OptionButtons are not suitable for me.
Is there any way to this scenario? Thanks in advance for any advice.

I just wrote this part of the code for my label and didn’t know how to write the rest:

Private Sub ExtUR_Label1_Click()
    ExtUR_Label1.Caption = "X"
    ExtUR_Label1.ForeColor = &H8000000D
End Sub

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

>Solution :

You have the right idea. Something like the following should do what you need:

Private Sub ExtUR_Label1_Click()
   If ExtUR_Label1.Caption = "1" Then
      ExtUR_Label1.Caption = "X"
   ElseIf ExtUR_Label1.Caption = "X" Then
      ExtUR_Label1.Caption = "?"
   Else
      ExtUR_Label1.Caption = "1"
   End If
End Sub
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