ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Summary problem (https://www.excelbanter.com/excel-programming/303223-summary-problem.html)

CG Rosén

Summary problem
 

Good Day Group,

I am stuck with this problem that might be easier then I think(?).
Grateful for any help.

Have data in columns A and B as below. Looking for to put values in column C
as shown, that is the sum of the values in B when the values in A are the
same.

Brgds

CG Rosén
????
A B C
040702 20
040702 10
040702 20 50
040703 20
040703 10 30
040704 10
040704 5
040704 20
040704 10
040704 5
040704 10 60
040710 25 25



Nick Hodge

Summary problem
 
If you truly need a programming option then the code below will work
providing the data in column A is contiguous

Sub sumSame()
Dim rRange As Range
Dim rCell As Range
Dim x As Double

Set rRange = Range("A1:" & Range("A65536").End(xlUp).Address)
For Each rCell In rRange
If rCell.Offset(1, 0).Value = rCell.Value Then
x = rCell.Offset(0, 1).Value + x
Else
rCell.Offset(0, 2).Value = x + rCell.Offset(0, 1).Value
x = 0
End If
Next rCell
End Sub

An alternative maybe to check out datasubtotals...

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"CG Rosén" wrote in message
...

Good Day Group,

I am stuck with this problem that might be easier then I think(?).
Grateful for any help.

Have data in columns A and B as below. Looking for to put values in column

C
as shown, that is the sum of the values in B when the values in A are the
same.

Brgds

CG Rosén
????
A B C
040702 20
040702 10
040702 20 50
040703 20
040703 10 30
040704 10
040704 5
040704 20
040704 10
040704 5
040704 10 60
040710 25 25






All times are GMT +1. The time now is 05:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com