Summing data in one column based on date in another column

J

Jon1234

Hi

I need something that would sum up column B only when it shared a column A
name...

e.g.

A3= Tom B3= $10
A4= Jim B4 = $5
A5= Tom B5 = $5
A6= Jim B6= $12
If possible the macro could generate a pdf that would display

Tom = $15
Jim = $17

This would be needed for multiple names (over 20), and varying currency.

Thank you for your time
 
C

Chip Pearson

This is well-suited for a Pivot Table.


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

JLGWhiz

This assumes that you have a list of names in column D for all members of the
group. You can put the list in any column and adjust the code accordingly.
It will find all occrrences of a name in column A and add all values for that
name which it places in Column E adjacent to that name for Column D.

You can then copy that data to a new sheet and create a PDF file if needed.

Sub addemup()
Dim lr As Long, c As Range, nm As Range, mySum As Double
lr = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
For Each c In Range("D2:D" & lr)
For Each nm In Range("A2:A" & _
Cells(Rows.Count, 1).End(xlUp).Row)
If nm = c Then
mySum = mySum + nm.Offset(0, 1).Value
End If
Next
c.Offset(0, 1) = mySum
Next
End Sub
 
J

Jon1234

This worked wonderfully...except I forgot one key aspect...in a few
circumstances there is an opposite payment type.

Column A= name
Column B= purchase type (buy or sell)
Column C = $$

So I need it to not only sort it by name but by name and purchase type...

Tom Sell 5
Tom Buy 10
Tom Buy 5
Jim Buy 5
Jim Buy 10
Jim Sell 1

Tom Sell 5
Tom Buy 15
Jim Buy 15
Jim Sell 1

I'll be tinkering with your original script, and hopefully get it to
work...the sum populating in E for Sale and F for Buy would work just fine
assuming the list is in D.

Thanks again.
 

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

Top