ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cycle through controls with similar names (https://www.excelbanter.com/excel-programming/321756-cycle-through-controls-similar-names.html)

Tim Archer[_2_]

Cycle through controls with similar names
 
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

Bob Phillips[_6_]

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





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com