PC Review


Reply
Thread Tools Rate Thread

How do I cycle through buttons in a FOR loop?

 
 
Morris
Guest
Posts: n/a
 
      1st Mar 2007
I've got this piece of code which is obsiously not working:

For i = 1 To Worksheets.Count
TempForm.CommandButton & i & .Caption = Worksheets(i).Name
Next i

But I need to assign different captions based on sheet names.. How do
I achieve that?

Cheers,
Morris

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      1st Mar 2007
try this
Sub getworksheetname()
For Each Myworksheet In ThisWorkbook.Worksheets
myname = Myworksheet.Name
Next Myworksheet

End Sub
>
> But I need to assign different captions based on sheet names.. How do
> I achieve that?
>
> Cheers,
> Morris
>
>

 
Reply With Quote
 
merjet
Guest
Posts: n/a
 
      1st Mar 2007
Assuming TempForm is a UserForm with CommandButtons:

On Error Resume Next
For i = 1 To Worksheets.Count
TempForm.Controls("CommandButton" & i).Caption =
Worksheets(i).Name
Next i

Hth,
Merjet

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to loop through option buttons Blahdee Microsoft Excel Misc 1 1st Dec 2009 01:43 PM
How to skip to the next cycle in a For Next loop Southern at Heart Microsoft Access VBA Modules 3 16th Feb 2008 05:06 PM
Cycle through radio buttons in a groupbox? =?Utf-8?B?RXJpYw==?= Microsoft Dot NET Framework Forms 4 17th Nov 2005 10:31 PM
Referencing Toggle Buttons in a loop =?Utf-8?B?RWRkaWUncyBCYWtlcnkgYW5kIENhZmUn?= Microsoft Access VBA Modules 2 1st Mar 2005 02:25 AM
How to cycle through a series of similar objects with a for-next loop? Derrick Vandekraats Microsoft Excel Programming 5 30th Sep 2004 04:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:59 AM.