adding array elements by index

eviMogwai

New Member
Joined
Jul 4, 2011
Messages
26
Thanks for stopping by =)

So, I have a reference array I want to build a subset of for use in a function.
The reference is a long array of values, the array I need will only need some of the values and as I know the positions in the reference, i thought I'd set up a for-loop.

Code:
dim vArr(), vRef
vRef = Array(10,20,30,40,50,60,70,80)
 
for i = 0 to 5
 
debug.print(vRef(i))
 
vArr(i) = vRef(i)
next

Unfortunately, this gives me an index out of bound for the first step in the for-loop.
The direct window gives an output of 10, so vRef(0) seems to work as it should.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top