# Is there a way to sum only certain elements of an array in vba(for large amounts of data)

#### WendyB5

##### New Member
I have an array in vba named ClmArray(1 to 50000000, 1 to 8) and I need to create a new array AnnualLosses(1 to 10000) each value needs to be the sum of ClmArray(1,8) to ClmArray(5000,8); ClmArray(5001,8) to ClmArray(10000,8); all the way to ClmArray(49995001,8) to ClmArray(50000000,8). Clearly I can't put this in excel & do the sum because there are not enough rows available, but I need those sums to then create points for a pdf function that I am doing as a project for 5000 vhicle claims each year. I am new to vba and if anyone has any suggestions or comments I would greatly appreciate them.
I would like to do all the work in vba then bin the annual losses and graph them against their frequency. I was going to do 10000 arrays each one being 1 year of losses for 5000 cars, but that would be a lot of repetitve code and also I still can't solve the probelm of only summing (i=1 to 5000,8) and not the entire array. There is probably an easier or more efficient way of doing this and I am open to all ideas. Thank you all so very much.

Last edited:

### Excel Facts

If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Maybe something like this...

Code:
``````    Dim AnnualLosses(1 To 10000) As Single
Dim i As Long, j As Long, k As Long
Dim tot As Single

For i = 1 To 10000
For j = 1 To 5000
k = j + ((i - 1) * 5000)
tot = tot + ClmArray(k, 8)
Next j
AnnualLosses(i) = tot
tot = 0
Next i``````

That worked great - I just needed to make my AnnualLosses(1 to 1000, 1 to 1) when posting on a spreadsheet. Thanks for the help AlphaFrog - you saved me from another night of tears.

Replies
6
Views
387
Replies
6
Views
64
Replies
5
Views
78
Replies
6
Views
325
Replies
5
Views
369

1,203,453
Messages
6,055,530
Members
444,794
Latest member
HSAL

### 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.

### Which adblocker are you using?

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

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