View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_2094_] Rick Rothstein \(MVP - VB\)[_2094_] is offline
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