PC Review


Reply
Thread Tools Rate Thread

Commandbutton captions

 
 
Al
Guest
Posts: n/a
 
      10th Jun 2008
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.
I’m looking for a simple loop to add captions from the list, but I don’t see
any way to index the button reference in a loop. What I’m trying to do:

For n = 1 to List Count
CommandButtonn.Caption = Range(“List”).Offset( n, 0)
Next

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

--
Al C
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      10th Jun 2008
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" <(E-Mail Removed)> skrev i meddelelsen
news:1BA787B1-3D15-49CE-9D13-(E-Mail Removed)...
>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.
> I’m looking for a simple loop to add captions from the list, but I don’t
> see
> any way to index the button reference in a loop. What I’m trying to do:
>
> For n = 1 to List Count
> CommandButtonn.Caption = Range(“List”).Offset( n, 0)
> Next
>
> Obviously that won’t work, so I seem to be headed for a brute force
> method.
> Is there a more elegant way?
>
> --
> Al C


 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      10th Jun 2008
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" <(E-Mail Removed)> wrote in message
news:1BA787B1-3D15-49CE-9D13-(E-Mail Removed)...
>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.
> I’m looking for a simple loop to add captions from the list, but I don’t
> see
> any way to index the button reference in a loop. What I’m trying to do:
>
> For n = 1 to List Count
> CommandButtonn.Caption = Range(“List”).Offset( n, 0)
> Next
>
> Obviously that won’t work, so I seem to be headed for a brute force
> method.
> Is there a more elegant way?
>
> --
> Al C


 
Reply With Quote
 
Al
Guest
Posts: n/a
 
      10th Jun 2008
Thank you both. That got me past a mental lblock.
--
Al C


 
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
Table captions converted to figure captions, & vice versa =?Utf-8?B?YnVmb3NzaWw=?= Microsoft Word Document Management 12 18th May 2007 08:10 AM
Row Captions AND Column Captions Possible? Dave Peterson Microsoft Excel Discussion 1 30th Apr 2005 04:15 PM
Captions, multiple captions on the same line =?Utf-8?B?YWxsYW4=?= Microsoft Word Document Management 1 8th Mar 2005 08:33 PM
CommandButton =?Utf-8?B?QWx2aW4gSGFuc2Vu?= Microsoft Excel Programming 4 9th Oct 2004 07:19 PM
Image Hot Spots with Captions: Mouse Roll Over to Display Captions? J. Danniel Microsoft Frontpage 6 27th Feb 2004 01:45 AM


Features
 

Advertising
 

Newsgroups
 


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