How to look a value and sum it into a certain cell

2

I have 2 columns, Space & Rows. I want to iterate over the Rows columns and sum only the corresponding value of Space into a certain cell within the same page.

The pseudo code for this would be like:

FOREACH (E2:E10 as N)
    IF (N == 1) B14 += N;
    IF (N == 2) C14 += N;
    IF (N == 3) D14 += N;

Where N would be the value of the current row it's looking over.


As far as the solution goes, I think it's easier to attack it from the point of view of the the cell that is going to get the value. In this case, that would be B14, C14 & D14. So in this case the function would be in each cell as pertains to itself only.

Something along the lines of:

=SUMIF(G2:G10, EXACT(GETCURRENTITEM(), 1), F2:F10)

=SUMIF(G2:G10, EXACT(GETCURRENTITEM(), 2), F2:F10)

=SUMIF(G2:G10, EXACT(GETCURRENTITEM(), 3), F2:F10)

I've recreated the spreadsheet in Google Docs, and if you can provide an answer for Excel or Google Docs that'd be great.

As far as Microsoft Office, I've looked up, SUMIF(), VLOOKUP() but the combination of these items is starting to look more like line noise then functions. I just can't quite wrap my head around it.

Mark Tomlin

Posted 2013-09-23T02:37:57.297

Reputation: 1 179

1Can you post a sample file with manually mocked up results? It's a bit hard to picture what you want to achieve. Why does a Sumif() not suffice? – teylyn – 2013-09-23T04:05:24.453

It looks like you are trying to iterate with sumif, but there is no need for iteration with it. – Raystafarian – 2013-09-23T08:58:52.280

Shit, I'm so sorry. I made a Google Doc but did not link to it. So there it is.

– Mark Tomlin – 2013-09-23T17:33:35.113

Answers

2

If SUMIF isn't given a sum_range, it simply sums the values it finds that meet the criteria. The simplest way to add the number of 1's is to ask SUMIF to check for them in cell B14:

=SUMIF($E$2:$E$20,1)

Similarly, we can check for and add the 2's in C14:

=SUMIF($E$2:$E$20,2)

Et cetera.

Excel Tactics

Posted 2013-09-23T02:37:57.297

Reputation: 364