Summary problem

  • Thread starter Thread starter CG Rosén
  • Start date Start date
C

CG Rosén

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
 
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 data>subtotals...

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top