bug in excel VBA?


  I encountered something very strange in Excel VBA. I have created a number of labels and want to control their visibility under a certain cases. For example, whenever I click on a button, the labels will toggle their visibility. I found that when the number of labels is less than 13, it works fine. Otherwise, some labels still show up even I set their visibility to be False..  Did anybody encounter this before? Is this a known bug? Any comment is appreciated!

Who is Participating?
MirkwoodConnect With a Mentor Commented:
No problem in Excel 97.

I tried the code below
   Label1.Visible = Not Label1.Visible
    Label2.Visible = Not Label2.Visible
    Label3.Visible = Not Label3.Visible
    Label4.Visible = Not Label4.Visible
    Label5.Visible = Not Label5.Visible
    Label6.Visible = Not Label6.Visible
    Label7.Visible = Not Label7.Visible
    Label8.Visible = Not Label8.Visible
    Label9.Visible = Not Label9.Visible
    Label10.Visible = Not Label10.Visible
    Label11.Visible = Not Label11.Visible
    Label12.Visible = Not Label12.Visible
    Label13.Visible = Not Label13.Visible
    Label14.Visible = Not Label14.Visible
    Label15.Visible = Not Label15.Visible
    Label16.Visible = Not Label21.Visible
    Label17.Visible = Not Label21.Visible
    Label18.Visible = Not Label21.Visible
    Label19.Visible = Not Label21.Visible
    Label20.Visible = Not Label21.Visible
    Label21.Visible = Not Label21.Visible
    Label22.Visible = Not Label22.Visible
    Label23.Visible = Not Label23.Visible
    Label24.Visible = Not Label24.Visible
    Label25.Visible = Not Label25.Visible
    Label26.Visible = Not Label26.Visible
    Label27.Visible = Not Label27.Visible
    Label28.Visible = Not Label28.Visible
    Label29.Visible = Not Label29.Visible
    Label30.Visible = Not Label30.Visible

Try DoEvents, to do forgotten events.

sunjian061197Author Commented:
Hi fguerreiro_inix:

  Would you pls elaberate more? You see my code might just look like following:

Sub command1_click()
end sub

However, after i click the command button, label13 is still visible...

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

What version of excel are you using?  I just tried what you said in Excel 97 - and all 13 labels got hidden.  I think there's something with your code.  Make sure you reference the names correctly.  Maybe, your 13th label has name different than 'label13' and you have 'on error resume next' or something like this so that it doesn't give you an error.

sunjian061197Author Commented:
ooops!!! My excel version is also Excel 97... Let me check and try again...

sunjian061197Author Commented:

  I still got problem when I do it in that computer... But after I changed to another PC, it's all fine. I checked out my typings very carefully and there shouldn't be any error....

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.