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 Name

Hi,

a little problem.

How can I access to my variables in a loop

Ex :

Dim Name1 as string
Dim Name2 as string
Dim Name3 as string

sub Test

Name1 = "X"
Name2 = "Y"
Name3 = "Z"
For i = 1 to 3
msgbox(*Name & i*) 'should display X then Y then Z
Next i
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variable Name

I tried that once before and never found a way of doing it- I don'
think it can be done. What you can do though is create an arra
(matrix) and loop though the elements- Be aware the first element i
indexed as zero not 1.

Dim arMyArray(2) as Long

For i = 0 to 2
armyarray(i) = i*5
next i

The variable will be:

arMyArray = (0,5,10)

and to get the values back out just specify the index-

arMyArray(1) = 5

Dunca

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Variable Name

Hi
use an array variable. e.g.
dim name(1 to 3) as string
dim i
name(1)="test1"
name(2)="test2"
name(3)="test3"
for i = 1 to 3
msgbox name(i)
next


-----Original Message-----
Hi,

a little problem.

How can I access to my variables in a loop

Ex :

Dim Name1 as string
Dim Name2 as string
Dim Name3 as string

sub Test

Name1 = "X"
Name2 = "Y"
Name3 = "Z"
For i = 1 to 3
msgbox(*Name & i*) 'should display X then Y then Z
Next i
End Sub


---
Message posted from http://www.ExcelForum.com/

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Variable Name

Hi

You have to use arrays in this situation:
Sub Test
Dim i As Long
Dim Name(1 to 3) As Variant

Name(1) = "X"
Name(2) = "Y"
Name(3) = "Z"
For i = 1 to 3
msgbox Name(i)
Next i
End Sub


--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"LadaDriver " skrev i en
meddelelse ...
Hi,

a little problem.

How can I access to my variables in a loop

Ex :

Dim Name1 as string
Dim Name2 as string
Dim Name3 as string

sub Test

Name1 = "X"
Name2 = "Y"
Name3 = "Z"
For i = 1 to 3
msgbox(*Name & i*) 'should display X then Y then Z
Next i
End Sub


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variable Name

good idea,

th

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Variable Name

You're welcome.

"LadaDriver " skrev i en
meddelelse ...
good idea,

thx



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Variable Name

Just to throw something out. I know this is most likely not useful, but
thought I would mention it. In "some" situations, the following "very
general idea" can simplify certain code.
A dedicated routine to update the Coll. helps.

Sub Demo()
Dim nm1
Dim nm2
Dim j
Dim v As New Collection

nm1 = "x"
nm2 = "y"

v.Add Array("nm1", nm1), "nm1"
v.Add Array("nm2", nm2), "nm2"

For j = 1 To v.Count
Debug.Print v(j)(0) & " holds - " & v(j)(1)
Next j
End Sub

Returns...

nm1 holds - x
nm2 holds - y



"Leo Heuser" wrote in message
...
You're welcome.

"LadaDriver " skrev i en
meddelelse ...
good idea,

thx





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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 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
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 01:21 AM.

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

About Us

"It's about Microsoft Excel"