Assigning One Array to Another
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
If two dynamic arrays have the same data type, you can assign one array to another. Assigning one array to another of the same type is quick because the first array is simply pointed to the memory location that stores the second array. This feature is new to this version of VBA; it's not available in previous versions.
For example, the following code fragment assigns one string array to another:
Dim astr1() As String Dim astr2(0 To 9) As String astr1 = astr2
Important This type of assignment works only for dynamic arrays of the same type. The two arrays must both be dynamic arrays, and they must be declared as the exact same type: if one is type String, the other must be type String. It can't be type Variant or any other data type. If you want to assign one array's elements to an array of a different type, you must create a loop and assign each element one at a time.