Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Commandbutton captions

I have a Userform that is initiated by user selection of certain cells, and I
need to display a number of CommandButtons corresponding to the length of a
list associated with the user selection. My form has the maximum number of
buttons I ever expect, and a macro sizes it to display only those needed.
Im looking for a simple loop to add captions from the list, but I dont see
any way to index the button reference in a loop. What Im trying to do:

For n = 1 to List Count
CommandButtonn.Caption = Range(€śList€ť).Offset( n, 0)
Next

Obviously that wont work, so I seem to be headed for a brute force method.
Is there a more elegant way?

--
Al C
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Commandbutton captions

Hi

Assuming the CommandButtons is named "CommandButton1", "CommandButton2"....

Try this code

For n = 1 To ListCount
For Each c In Me.Controls
If c.Name = "CommandButton" & n Then
c.Caption = Range("List").Offset(n, 0).Value
Exit For
End If
Next
Next

Regards,
Per

"Al" skrev i meddelelsen
...
I have a Userform that is initiated by user selection of certain cells, and
I
need to display a number of CommandButtons corresponding to the length of
a
list associated with the user selection. My form has the maximum number
of
buttons I ever expect, and a macro sizes it to display only those needed.
Im looking for a simple loop to add captions from the list, but I dont
see
any way to index the button reference in a loop. What Im trying to do:

For n = 1 to List Count
CommandButtonn.Caption = Range(€śList€ť).Offset( n, 0)
Next

Obviously that wont work, so I seem to be headed for a brute force
method.
Is there a more elegant way?

--
Al C


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Commandbutton captions

Try it this way...

Private Sub UserForm_Initialize()
Dim N As Long
For N = 1 To Range("List").Count
Me.Controls("CommandButton" & N).Caption = _
Range("List").Cells(N, 1).Value
Next
End Sub

Rick


"Al" wrote in message
...
I have a Userform that is initiated by user selection of certain cells, and
I
need to display a number of CommandButtons corresponding to the length of
a
list associated with the user selection. My form has the maximum number
of
buttons I ever expect, and a macro sizes it to display only those needed.
Im looking for a simple loop to add captions from the list, but I dont
see
any way to index the button reference in a loop. What Im trying to do:

For n = 1 to List Count
CommandButtonn.Caption = Range(€śList€ť).Offset( n, 0)
Next

Obviously that wont work, so I seem to be headed for a brute force
method.
Is there a more elegant way?

--
Al C


  #4   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Commandbutton captions

Thank you both. That got me past a mental lblock.
--
Al C


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
X axis captions Stefi Charts and Charting in Excel 6 September 11th 08 01:16 PM
label captions randy Excel Programming 4 May 27th 08 01:34 AM
Labels and Captions [email protected] Excel Programming 2 March 9th 07 04:26 AM
How do I put captions on Excel charts? pgrizzell Charts and Charting in Excel 1 June 8th 06 10:14 PM
Userform Captions Greg[_27_] Excel Programming 3 May 23rd 06 07:23 PM


All times are GMT +1. The time now is 07:21 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"