Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sequential variables (no array)
Hi,
is possible in the code using a for next for assign a value to a sequential variables (no array)? I mean, instead of this... aa1 = 9 aa2 = 9 aa3 = 9 ....... aa100 = 9 use: for x = 1 to 100 aa&"x" = 9 -- I do not know the correct syntax !!! next x No array aa(x) please. Thanks to all R. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sequential variables (no array)
Hi,
Am Mon, 31 Jul 2017 01:35:55 -0700 (PDT) schrieb : aa1 = 9 aa2 = 9 aa3 = 9 ...... aa100 = 9 you don't need a loop. Try: Range("AA1:AA100")=9 Regards Claus B. -- Windows10 Office 2016 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sequential variables (no array)
Il giorno lunedì 31 luglio 2017 10:41:29 UTC+2, Claus Busch ha scritto:
Hi, Am Mon, 31 Jul 2017 01:35:55 -0700 (PDT) schrieb: aa1 = 9 aa2 = 9 aa3 = 9 ...... aa100 = 9 you don't need a loop. Try: Range("AA1:AA100")=9 Regards Claus B. -- Windows10 Office 2016 Thanks Claus, but they are vba variables not cells. Bye |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sequential variables (no array)
reinquisito2 wrote:
is possible in the code using a for next for assign a value to a sequential variables (no array)? I mean, instead of this... aa1 = 9 aa2 = 9 aa3 = 9 ...... aa100 = 9 use: for x = 1 to 100 aa&"x" = 9 -- I do not know the correct syntax !!! next x No array aa(x) please. Why not? This is one of the reasons arrays exist. There is nothing built into VBA that will let you do as you ask. You could probably do this using, say, self-modifying code, but that opens a whole new can of worms, and is definitely not for beginners. What *exactly* are you trying to accomplish? *Why* don't you want to use an array? -- - I'm going to free them. - Why? - Because it's the right thing to do, you narrow-minded jackass. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sequential variables (no array)
Il giorno lunedì 31 luglio 2017 12:55:06 UTC+2, Auric__ ha scritto:
reinquisito2 wrote: is possible in the code using a for next for assign a value to a sequential variables (no array)? I mean, instead of this... aa1 = 9 aa2 = 9 aa3 = 9 ...... aa100 = 9 use: for x = 1 to 100 aa&"x" = 9 -- I do not know the correct syntax !!! next x No array aa(x) please. Why not? This is one of the reasons arrays exist. There is nothing built into VBA that will let you do as you ask. You could probably do this using, say, self-modifying code, but that opens a whole new can of worms, and is definitely not for beginners. What *exactly* are you trying to accomplish? *Why* don't you want to use an array? -- - I'm going to free them. - Why? - Because it's the right thing to do, you narrow-minded jackass. Ok Auric, I rewrite code using array. Thanks BR |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Sequential variables (no array)
There is nothing built into VBA that will let you do as you ask. One way, if variables names must beginning with underscore char (to avoid problems with cell names) is to use "named ranges": Sub createNames() 'run only one time Dim j As Long For j = 1 To 100 ThisWorkbook.Names.Add Name:="_aa" & j, RefersTo:=0, Visible:=False Next End Sub Sub writeNames() Dim j As Long 'run only one time For j = 1 To 100 ThisWorkbook.Names("_aa" & j).RefersTo = 9 Next End Sub Sub readNames() Dim j As Long 'run only one time For j = 1 To 10 Debug.Print Application.Evaluate(ThisWorkbook.Names("_aa" & j).RefersTo) Next End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
clearing array variables and using an array to determine min value | Excel Programming | |||
Array variables | Excel Programming | |||
Creating sequential variables on the fly | Excel Programming | |||
How can I create an array formula for non-sequential cells | Excel Worksheet Functions | |||
Non-sequential VLOOKUP function -OR- sequential sort of web query | Excel Worksheet Functions |