View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
[email protected] scossa.vr@gmail.com is offline
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