This is a matter of personal curiosity.
In VBA, if I have an array of size 2:
Dim r(1) as Variant
And I want both values in the array to be -1. I can do this:
r(0)=-1
r(1)=-1
Or I could iterate through both with a loop and set them to -1.
So my question is, is there any way I can set all the values in an array to the same thing without iterating?
Or, is there any way I can do something like:
r = array(-1,-1)
This might be a really stupid question but I can’t seem to find the answer.
Yes you can do it. But then you have to take care while declaring the array
Example
FOLLOWUP
See the Excel Help File 🙂 The Array Function returns a
Variantcontaining anarray. You cannot assign an array to another array directly. To assign an array to another array you have to use this method.