Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default How do I cycle through buttons in a FOR loop?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How do I cycle through buttons in a FOR loop?

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default How do I cycle through buttons in a FOR loop?

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make a graph with 2-cycle X 3-cycle log-log graph paper? Charles A. Wilson Charts and Charting in Excel 1 December 17th 09 03:03 AM
how to loop through option buttons Blahdee Excel Discussion (Misc queries) 1 December 1st 09 01:43 PM
How do I keep result from 1 iteration cycle to use in next cycle? sgl8akm Excel Discussion (Misc queries) 0 July 27th 06 08:28 PM
How do I cycle through all of the worksheets DMB Excel Discussion (Misc queries) 1 January 9th 06 12:21 AM
How to cycle through a series of similar objects with a for-next loop? Derrick Vandekraats Excel Programming 5 September 30th 04 04:22 AM


All times are GMT +1. The time now is 01:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"