Sum all repeated values in consecutive order

15dgs

New Member
Joined
Jun 16, 2017
Messages
5
Fruit
#
Total
Apple
2
8
Apple
6
NO VALUE
Orange
7
7
Apple
9
9
Banana
1
15
Banana<strike></strike>
10
NO VALUE<strike></strike>
Banana<strike></strike>
4
NO VALUE<strike></strike>

<tbody>
</tbody>


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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,215,432
Messages
6,124,858
Members
449,194
Latest member
HellScout

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