Sum all repeated values in consecutive order

15dgs

New Member
Joined
Jun 16, 2017
Messages
5
[TABLE="width: 500"]
<tbody>[TR]
[TD]Fruit
[/TD]
[TD]#
[/TD]
[TD]Total
[/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD]2
[/TD]
[TD]8
[/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD]6
[/TD]
[TD]NO VALUE
[/TD]
[/TR]
[TR]
[TD]Orange
[/TD]
[TD]7
[/TD]
[TD]7
[/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD]9
[/TD]
[TD]9
[/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD]1
[/TD]
[TD]15
[/TD]
[/TR]
[TR]
[TD]Banana<strike></strike>
[/TD]
[TD]10
[/TD]
[TD]NO VALUE<strike></strike>
[/TD]
[/TR]
[TR]
[TD]Banana<strike></strike>
[/TD]
[TD]4
[/TD]
[TD]NO VALUE<strike></strike>
[/TD]
[/TR]
</tbody>[/TABLE]


How do I consolidate a column but only if they're in consecutive order? I can't just use the consolidate feature because that will total all of the apples but I only want to total them if they come right in a row. Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi - welcome to the board.

Can you be a bit more specific - given the data you've provided, what results are you trying to produce..?
 
Upvote 0
Hi - welcome to the board.

Can you be a bit more specific - given the data you've provided, what results are you trying to produce..?

Sure! So basically I have a string of a few thousand lines of data that's similar to the table above that I need to analyze for a pattern. However, the device that recorded my data gave results back ever few milliseconds even if it was the same result for numerous seconds in a row. So I now need an equation that will sum the amount of time on each stimulus that happened back to back but I can't have it compromise the order it occurred in. Does that make more sense? Thanks!
 
Upvote 0
See if this VBA sub works for you:
Code:
Sub Sum_Rpt_Val()
    Dim cll As Range, out As Range, ttl As Double
    Set out = Range("C2")
    ttl = Range("B2").Value
    For Each cll In Range([A2], Cells(Rows.Count, "A").End(xlUp).Offset(1))
        If cll.Value = cll.Offset(-1).Value Then
            ttl = ttl + cll.Offset(, 1).Value
        Else
            out.Value = ttl
            ttl = cll.Offset(, 1).Value
            Set out = cll.Offset(, 2)
        End If
    Next cll
End Sub
 
Upvote 0
I love you. You are a genius. I have very limited knowledge of VBA's but this worked. Thank you!
 
Upvote 0
In C2 control+shift+enter, not just enter, and copy down:

=IF($A2=$A1,"NO VALUE",SUM(OFFSET($B2,0,0,MAX(FREQUENCY(IF(A2:$A$8=$A2,ROW(A2:$A$8)),IF(1-(A2:$A$8=$A2),ROW(A2:$A$8)))))))
 
Upvote 0

Unknown
ABC
1Fruit#Total
2Apple28
3Apple6NO VALUE
4Orange77
5Apple99
6Banana115
7Banana10NO VALUE
8Banana4NO VALUE
Sheet6
Cell Formulas
RangeFormula
C2{=IF(A2=A1,"NO VALUE",SUM(B2:INDEX(B2:B$8,MIN(IF(A2:A$8<>A3:A$9,ROW(A2:A$8)-ROW(A2)+1)))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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