Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
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
clearing array variables and using an array to determine min value NDBC Excel Programming 7 September 4th 09 09:43 PM
Array variables xavi garriga Excel Programming 3 February 21st 09 11:28 PM
Creating sequential variables on the fly ForestRamsey Excel Programming 3 November 16th 05 08:11 AM
How can I create an array formula for non-sequential cells Sue Excel Worksheet Functions 7 May 21st 05 02:32 PM
Non-sequential VLOOKUP function -OR- sequential sort of web query Eric S Excel Worksheet Functions 1 February 28th 05 07:50 PM


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

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"