View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Variable Name Changes in Loop Operation

on 7/25/2011, LiCal supposed :
I am testing two variables of similarly named and sequentially
numbered through a do..loop.

I know that I can do that via var() array.

but if I want to change the variable name via string changes, how to
do it?

.......
day_1 = date
day_2 = dateadd("d", 7, day_1)

nn=1

do
msgbox "day_" & nn ' not working this way,
nn= nn+1
loop until nn=3

............

........


You could use a For...Next loop and use the counter like so...

Dim i As Integer
For i = 1 To 3
MsgBox "Day_" & CStr(i)
Next 'i

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc