Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default 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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 05:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"