Can you post your exact code? I think you are confusing setting the values of
array elements with adding items to a collection, or setting two object
variables to point to the same object.
First of all, Array is a reserved work. You shouldn't be trying to use it as a
variable name.
A variable name is simply some text that you use to make it easier to refer to
a particular address in memory. You can't "put one variable inside another"
(but see comments later). So Array(1) (or, better, Ary(1) can't "contain"
Var1. It contains a value.
Let's say you wrote
Dim Ary() As Variant
Redim Ary(1 to 2)
Dim Var1 As Variant
Var1 = "abc"
Ary(1) = Var1
The first 3 lines created 3 variables, with the names Ary(1), Ary(2), and
Var1.
The last 2 statements assign values to two of them. The last statement assigns
the value to Ary(1) by copying the value from the memory space that you refer
to with the name Var1 and pasting it into the memory space that you refer to
by the name Ary(1). It doesn't "put var1 inside" of Ary(1). Ary(1) and Var1
are separate and independent variables. Changing the value of one of them
doesn't affect the other.
There's an exception to my statement above about one variable not containing
another. That has to do with collections and object variables. The value of an
object variable is actually the memory address of another variable.
Collections are an array of object variables. When you add items to the
collection, you create a new object variable and assign it a value. I just
tried the following code. If you expect to print 1 and 2 the first time, then
-1 and -2 the second, that doesn't happen. The object in the collection is now
totally separate from the variable that provided its initial value. And I
don't see a way to change the value once you've added an item to the
collection. e.g. if you remove the apostrophe from the line just above the End
Sub line, you get an error.
Sub Test()
Dim Coll As Collection
Dim Var1 As Double
Dim Var2 As Double
Var1 = 1
Var2 = 2
Set Coll = New Collection
Coll.Add Var1, "Var1"
Coll.Add Var2, "Var2"
Debug.Print Coll("Var1")
Debug.Print Coll("Var2")
Var1 = -1
Var2 = -2
Debug.Print Coll("Var1")
Debug.Print Coll("Var2")
'Coll("Var1") = -1
End Sub
But somehow I don't think you have any need to work with collections and
objects here, do you? You just want to save several numbers using one variable
name with indices, i.e. an array. Can you describe what your ultimate goal is?