Array1 = Array2 ?

  • Thread starter Thread starter Jeffrey Marcellus
  • Start date Start date
J

Jeffrey Marcellus

Hi, is there any way short of nested for loops to set one array equal to
another? I've dimmed them to be the same size and of integer type, and just
want to make a backup of the first array.
Thanks for any help you all can provide.
Jeff
 
Alan,

Are you sure this works? I get a "Can't assign to array" compiler
error.
 
I get the same thing. If you dim Array2 as Variant, you can do it.
 
Thanks Dick. I do wonder however, how much more memory the (25,25) integer
array is taking up as a variant array...
Jeff
 
With 1-5 in range A1:A5,

Sub test3001()
Dim Array1() As Integer, Array2() As Integer

'You can substitute for the following
'line anything that loads Array1
Assign Range("A1:A5"), Array1

For Each Elem In Array1
Debug.Print Elem 'This returns 1-5
Next

Array2 = Array1

For Each Elem In Array2
Debug.Print Elem 'This returns 1 to 5
Next

'The next line returns Integer() Integer()
Debug.Print TypeName(Array1), TypeName(Array2)
End Sub

How the hell are ya', Chip?

Alan
 
Alan,

Yes, your code works with dynamic arrays. I tested with static
arrays and got an error.
 
Without seeing your code or Chip's, I can only guess at your problem;
but my guess is that you did not declare Array2 as a dynamic array.

Alan Beban
 
I was so taken with the idea of the answer being virtually the same as
the question that I overlooked mentioning the important requirement of
declaring a dynamic array. Sorry.

Alan Beban
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top