For ..... next loop for changing button captions

  • Thread starter Thread starter Arkimediz
  • Start date Start date
A

Arkimediz

I have 64 command buttons on a sheet that display the
names of the school classes and need to be automatically
updated at times. How do I put them in a loop instead of
having 64 lines of instructions. I know below doesn't
work, but what will?

For ClassNumber = 1 To 64
Sheets("Forms").ClassName & ClassNumber.Caption =
NextFormName
Next ClassNumber

HELP!!!!!!!!!!!!!!
 
for i = 1 to 64
Sheets("Forms").OleObjects("CommandButton" & i).Object.Caption = _
NextFormName
Next

If your buttons have sequential numbers on the end of the name.
 
Thank you for that - I've tried it and it work superbly
but I need to hide the buttons that are not used. Why
doesn't it work on the "Visible = TRUE" object instead
of "Caption = "XXXXXX""
 
for i = 1 to 64
Sheets("Forms").OleObjects("CommandButton" & i).Object.Caption = _
NextFormName
Next

Not sure on which condition to check for, but try

Sheets("Forms").OleObjects("CommandButton" & i).Visible = False

The OleObject itself has the visible property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top