Solved

Sum matching rows to another sheet

Posted on 2011-03-02
8
269 Views
Last Modified: 2012-06-27
Hello Experts,

Here is what I have
SHEET 1
Name	ID	Pay
Mark	101	10
Phil	102	8
Dave	103	4
Mark	101	19
Dawn	104	4
Bob	105	60
Mark	101	7
Les	106	22
Dawn	104	31
Phil	102	40
Dave	103	11
Al	107	3
Les	106	12

Open in new window


I also have this in another sheet
SHEET 2
Name	ID     Pay  
Mark	101
Phil	102
Dave	103
Dawn	104
Bob	105
Les	106
Al	107

Open in new window


What I would like to do is fill in the Pay on SHEET 2 with the SUM of all the matching rows on SHEET1.  I assume a VLOOKUP on the ID would be best.
This is what SHEET2 will look like:
Name	ID	Pay
Mark	101	36
Phil	102	48
Dave	103	15
Dawn	104	35
Bob	105	60
Les	106	34
Al	107	3

Open in new window




I would like to know the simple formula that does it AND if there is a VB that will do it too.  I will use the formula, but I am learning VB and would like to see that too if possible.

THANKS!!!!
0
Comment
Question by:Mark Harris
  • 5
  • 2
8 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 35020621
Please check the attached example.

jppinto
Book1.xlsx
0
 
LVL 33

Expert Comment

by:jppinto
ID: 35020632
This is the formula to put on the first row under Pay:

=SUMPRODUCT((Sheet1!$A$2:$A$14=Sheet2!A2)*(Sheet1!$B$2:$B$14=Sheet2!B2)*(Sheet1!$C$2:$C$14))

Then copy down the column.

jppinto
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 35021092
Would SUMIF be sufficient, I assume the IDs are unique. In sheet 2 C2 copied down

=SUMIF(Sheet1!B:B,B2,Sheet1!C:C)

regards, barry
0
 
LVL 33

Expert Comment

by:jppinto
ID: 35021496
@fireman7147: did you at least took a look at my example?!? My formula works and gives the result that you wanted. I posted a working solution first and you accepted only the solution from barry?!

Please explain...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 50

Expert Comment

by:barry houdini
ID: 35021643
With respect jppinto, why would you need SUMPRODUCT here, SUMIF is always preferable for a single condition? I note that fireman7147 asked for a "simple formula", and that's what I provided - the first solution posted isn't necessarily the best!

regards, barry
0
 
LVL 33

Expert Comment

by:jppinto
ID: 35022685
Barry, with all due respect, you can use SUMIF here but you can also use SUMPRODUCT and it works. There are many ways of doing this. These are only two. I still think that at least my answer should be accepted as an "assist" because it works and I posted a working solution first. Maybe it's not the best solution, but still is a solution!

I would like to ear the explanation from the author here also...

regards,

jppinto
0
 

Author Comment

by:Mark Harris
ID: 35023582
@jppinto
Your solution worked indeed, but only if I had exactly the amount of rows in the example. Barry's solution worked with unlimited rows, which will be the case.

Sorry if you feel slighted, but his solution appeared to be the simplest and the most versatile. Any slight to you was unintentional.

Thanks Mark
0
 
LVL 33

Expert Comment

by:jppinto
ID: 35025409
OK, thanks for your feedback. No hard feelings. Maybe next time I get it :)

regards,

jppinto
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now