Add Cell base on another cell text

Ricky_J

New Member
Joined
Feb 3, 2016
Messages
15
Hello everybody,

Probably an easy question for everybody here.
I want to add multiple cells base on another cell text.

For example I want to add D7 if B8 says UTO with H7 if J8 says UTO.
I dont want D7 to add up with H7 if another text is included in D8 or J8.

=COUNTIF(D7=if=(B8="UTO"),H7=if(F8="UTO"))

I know the formula is incorrect, that's were I need you guys help.

Thank you
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I am afraid that your question is not quite clear.

Can you post a few examples of what is in D7, H7, B8, and F8, along with what you expected results in each case should be?
 
Upvote 0
Try this:
Code:
=SUMPRODUCT(--(B8:R8="UTO"),--(MOD(COLUMN(D7:T7),4)=0),--(D7:T7))
This sums the values in those cells in row 7 you referenced if their corresponding values in row 8 are "UTO".
 
Upvote 0
That's it.
My skills are very basic. I'll just have to learn how to decode this formula for the future.
Thank you very much.
Your help is much appreciated.
 
Upvote 0
If row 8, if the "UTO" values would only ever appear in those four columns you mentioned, you could get away with a simpler SUMIFS formula like this:
Code:
=SUMIFS(D7:T7,B8:R8,"UTO")

But if the following situation could exist:
- a value of "UTO" in cell C8 (not one of your mentioned columns)
- a numeric value in cell E7 (not one of your mentioned columns)
That value would be picked up by the SUMIFS formula (when you do not want it to).

SUMPRODUCT can be use in place of any COUNTIF, COUNTIFS, SUMIF, or SUMIFS formula, but has more flexibility than those.
(for a write-up on SUMPRODUCT and how that all works, see: https://www.ablebits.com/office-add...duct-function-formula-examples/#Conditionally)

The SUMIFS formula above I listed would look like this as a SUMPRODUCT formula:
Code:
=SUMPRODUCT(--(B8:R8="UTO"),--(D7:T7))
So, all that I did was add another condition to that SUMPRODUCT.
Code:
MOD(COLUMN(D7:T7),4)=0
While kind of daunting looking at first, it isn't so bad when you see what is going on.
The columns you wanted to check, D, H, L, P and T, are the 4th, 8th, 12th, 16th, and 20th columns respectively.
What do they all have in common? They are all multiple of 4!

The Excel COLUMN function return the column number for any cell. For example:
=COLUMN(D7)
would return 4
So we can use that function to get the column number of the cells we are working across.

The MOD function gives us a remainder when the first number is divided by the second.
So in the formula, we are dividing the column number by 4 to see what our remainder is.
Since all the columns we want to consider are multiples of 4, their remainders when divided by 4 is 0.
So this condition ensures that we are only include columns that are multiples of four.

I hope that helps clarify things a little.
 
Upvote 0
It does thank you very much.
But what if the columns I want to add are no longer multiple of 4, how could i implement that in the rule?
For example what if I wanted to add E7, I7,M7,Q7 and U7
Instead of D7,H7,L7,P7,T7?
They no longer share a commun denominator since it would be column 5, 9, 13, 17 and 21.
 
Upvote 0
They no longer share a commun denominator since it would be column 5, 9, 13, 17 and 21.
It still works, since the "jumps" are still 4. Remember, the MOD function returns the remainder.
When divided by 4, all those numbers have the same remainder (namely, 1).
So instead of this:
Code:
MOD(COLUMN(D7:T7),4)=0
you would have this:
Code:
MOD(COLUMN(E7:U7),4)=1
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top