Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel SUMIF when another cell contains text

So for example purposes, I have the following table:

|    |     A      |    B     |
|    |------------|----------|
|  1 |Description |Amount    |
|  2 |------------|----------|
|  3 |Item1       |      5.00|
|  4 |Item2**     |     29.00|
|  5 |Item3       |      1.00|
|  6 |Item4**     |      5.00|
|  7 |------------|----------|
|  8 |Star Total  |     34.00|
|  9 |------------|----------|

I want to create a formula in B8 that calculates the sum of the amounts if the description of that amount contains "**" (or some other denoting text). In this particular example I would like a formula that returns 34 since only Item2 and Item4 contain "**".

I tried to use something like this, but it only worked based on the value in A3:

=SUMIF(A3:A6, ISNUMBER(SEARCH("**", A3)), B3:B6)

Any suggestions would be appreciated!

like image 655
David Avatar asked Feb 08 '15 22:02

David


People also ask

How do I sum cells based on text in another cell?

Sum if cell contains text If you are looking for an Excel formula to find cells containing specific text and sum the corresponding values in another column, use the SUMIF function. Where A2:A10 are the text values to check and B2:B10 are the numbers to sum. To sum with multiple criteria, use the SUMIFS function.

How do I use Sumifs with text criteria?

The SUMIF function is conditional if the function used to sum the cells based on certain criteria, not the criteria can be a certain text too. For example, we want to sum up a group of cells. If the adjacent cell has a specified text, we can use the function: =SUMIF(Text Range,” Text,” cells range for sum).

How do you sum cells if another cell meets criteria?

If you want, you can apply the criteria to one range and sum the corresponding values in a different range. For example, the formula =SUMIF(B2:B5, "John", C2:C5) sums only the values in the range C2:C5, where the corresponding cells in the range B2:B5 equal "John."

Can Sumifs criteria reference a cell?

You can provide cell references as arguments of the SUMIFS function.


2 Answers

The asterisk is the wildcard symbol that can be used in Sumif(), so you may want to change the denoting text to some other symbols, for example @@. Then this formula will work:

=SUMIF(A2:A10,"*@@*",B2:B10)

enter image description here

If you want to keep the asterisks, the formula gets a bit curlier.

=SUMIF(A2:A10,"*~*~**",B2:B10)

The two middle asterisks are escaped with the tilde character.

enter image description here

like image 114
teylyn Avatar answered Oct 19 '22 21:10

teylyn


You can escape the wildcard character and turn it into a literal * by prefixing it with a swung dash (tilde, ~) and so leave your data unchanged:

=SUMIF(A2:A7,"*~*~*",B2:B7)  

IMO worthwhile because astrisks are relatively 'elegant'.

like image 34
pnuts Avatar answered Oct 19 '22 20:10

pnuts