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

WendyB5

New Member
Joined
Oct 28, 2011
Messages
2
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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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
 
Upvote 0
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. :)
 
Upvote 0

Forum statistics

Threads
1,224,389
Messages
6,178,299
Members
452,839
Latest member
grdras

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