![]() |
Variable variable name?!!?
say you have 3 textboxes called txt1, txt2 and txt3. It's possible to cycle thru these controls by using the following... for i = 1 to 3 msgbox .controls("txt" & i).value next i can this be done with variables names? i.e. variable1, variable2, variable3 help gratefully accepted! Thanks, Matt -- MattShoreso ----------------------------------------------------------------------- MattShoreson's Profile: http://www.excelforum.com/member.php...nfo&userid=347 View this thread: http://www.excelforum.com/showthread.php?threadid=57142 |
Variable variable name?!!?
That should work.
variable1 = "txt1" MsgBox Userform1.Controls(variable1).value Charles MattShoreson wrote: say you have 3 textboxes called txt1, txt2 and txt3. It's possible to cycle thru these controls by using the following... for i = 1 to 3 msgbox .controls("txt" & i).value next i can this be done with variables names? i.e. variable1, variable2, variable3 help gratefully accepted! Thanks, Matt. -- MattShoreson ------------------------------------------------------------------------ MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472 View this thread: http://www.excelforum.com/showthread...hreadid=571424 |
Variable variable name?!!?
No, not possible.
Create an array, and cycle through that aryValues = Array(1,2,3,4) For i = Lbound(aryValues) to Ubound(aryValues) MsgBox aryValues(i) Next i -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "MattShoreson" wrote in message news:MattShoreson.2cjcr4_1155568508.9407@excelforu m-nospam.com... say you have 3 textboxes called txt1, txt2 and txt3. It's possible to cycle thru these controls by using the following... for i = 1 to 3 msgbox .controls("txt" & i).value next i can this be done with variables names? i.e. variable1, variable2, variable3 help gratefully accepted! Thanks, Matt. -- MattShoreson ------------------------------------------------------------------------ MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472 View this thread: http://www.excelforum.com/showthread...hreadid=571424 |
Variable variable name?!!?
thanks bob. Realised that I had to do it this way. Think it's getting a little late in the day! A collection of variables = an array! -- MattShoreson ------------------------------------------------------------------------ MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472 View this thread: http://www.excelforum.com/showthread...hreadid=571424 |
Variable variable name?!!?
this should do what you want. mine are textbox1 thru textbox3
Private Sub CommandButton1_Click() For i = 1 To 3 MsgBox Me.Controls("textBox" & i) Next End Sub -- Gary "MattShoreson" wrote in message news:MattShoreson.2cjcr4_1155568508.9407@excelforu m-nospam.com... say you have 3 textboxes called txt1, txt2 and txt3. It's possible to cycle thru these controls by using the following... for i = 1 to 3 msgbox .controls("txt" & i).value next i can this be done with variables names? i.e. variable1, variable2, variable3 help gratefully accepted! Thanks, Matt. -- MattShoreson ------------------------------------------------------------------------ MattShoreson's Profile: http://www.excelforum.com/member.php...fo&userid=3472 View this thread: http://www.excelforum.com/showthread...hreadid=571424 |
All times are GMT +1. The time now is 05:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com