Dynamic Array Summation

akuzucu

New Member
Joined
Jan 22, 2011
Messages
2
Hi all,

I am looking forward to see your suggestions for my excel problem:

I have consecutive arrays all of which are in descending order in Column A. Each array starts from a random number and always ends up with 1. Each array is seperated from other by random variables. For each number in array there is a corresponding value in column B. What I want to do is to find out the sum of numbers in column B for each consecutive set.

To give an example: I want to find out and show the sum for row 1 to 4 (A have consecutive numbers) on B1 which is 11. Then, ignore row 5. Then starts another consecutive set. Find its sum and show the result on row 6 which is 27. The issue is I do not know the length of each array, it is variable.

----A-- B
1 -- 7 - 5
2 -- 6-- 1
3-- 5--- 2
4 --4 -- 3
5 --1 --6
6 --4 --9
7 --3 --4
8 --2 --6
9 --1 --8
10 -7 --2
11 -3 --1
12 -2 --0
13 -1 --5

Thanks!
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try this:-
Results in "C".
Code:
[COLOR="Navy"]Sub[/COLOR] MG24Jan52
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Twn [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Q
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    n = n + 1
        Twn = Dn + n
    [COLOR="Navy"]If[/COLOR] Not .Exists(Twn) [COLOR="Navy"]Then[/COLOR]
        .Add Twn, Array(Dn, Dn.Offset(, 1))
    [COLOR="Navy"]Else[/COLOR]
        Q = .Item(Twn)
        Q(1) = Q(1) + Dn.Offset(, 1)
        Q(0).Offset(, 2).Value = Q(1)
        .Item(Twn) = Q
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,622
Messages
6,125,886
Members
449,269
Latest member
GBCOACW

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