View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Cycle through controls with similar names


For i = 1 To 6
Me.Controls("txt" & i).Text = i
Next i

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Tim Archer" wrote in message
...
I have made a user form which allows the user to select a
number of groups all with the same parameters. Hence, I
have 6 of every control used for selection (text boxes
and combo boxes) and I have named the txt1, txt2, through
to txt6. I want to be able to do the same thing to each
control within a loop like you could do if these were
named ranges (e.g. Range("txt" & grp)). Is there a way
to do this?

I had also thought of directly linking each text box to a
cell using the ControlSource property. The problem is
that I want to be able to move these ranges if I need to
so that I can add more options later. I have found that
if you enter an address then this does not get moved if
you move the cell. I tried linking them to a named range
but this also seems to continue linking to the original
cell rather than moving to the range where the name is
now.

Can somebody point me in the direction of some useful
instructions on either cycling through control names or
linking directly to cells or towards a more efficient
method.

Thanks!

Tim