View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Refering to an object with a variable

That is pretty much it. You just need to package it in the initialize event
in the userforms code module

Private Sub Userform_Initialize()
Dim x as Long
Dim cb as MSForms.CommandButton
for x = 1 to 20
set cb = me.Controls("Button" & x)
cb.Caption = Sheet1.Cells(2, x + 2).Value
Next
end sub

--
Regards,
Tom Ogilvy


"Cory" wrote:

I have a userform with a number of Command Buttons (Button1, Button2,
etc...). Before the form loads, I would like to change the caption of each
of the buttons (with the use of a loop) to the contents of certain cells.
Can anyone help me with the syntax is to do so. For example:

For x = 1 to 20
ProjectForm.("Button" & x).Caption = Sheet1.Cells(2, x + 2)