Note: The other languages of the website are Google-translated. Back to English
English English

Sum if cells contain specific text in another column

This tutorial will show you how to sum values if cells contain specific or partial text in another column. Take the below data range as an example, to get the total amounts of the products containing the text “T-Shirt”, both the SUMIF function and SUMPRODUCT function can deal with this task in Excel.


Sum values if cell contains specific or partial text with SUMIF function

To sum values if a cell contains specific text in another column, you can use the SUMIF function with a wildcard (*), the generic syntaxes are:

Generic formula with hardcoded text:

=SUMIF(range,"*text*",sum_range)
  • range: The data range you want to evaluate using the criteria;
  • *text*: The criteria you want to sum values based on. Here, the * wildcard is used to find any number of characters, to match all items that contain a specific text, put the text between the two * characters. (Note that you must enclose the text and wildcard in double quotes.)
  • sum_range: The range of cells with matched numeric values that you want to sum.

Generic formula with cell reference:

=SUMIF(range,"*"&cell&"*",sum_range)
  • range: The data range you want to evaluate using the criteria;
  • "*"&cell&"*": The criteria you want to sum values based on;
    • *: The wildcard which finds any number of characters.
    • cell: The cell contains the specific text to look for.
    • &: This concatenation operator (&) is used to join a cell reference with the asterisks.
  • sum_range: The range of cells with matched numeric values that you want to sum.

After knowing the basic operation of the function, please use any one of the following formulas you need, and then press Enter key to get the result:

=SUMIF($A$2:$A$12,"*T-shirt*",$B$2:$B$12)                     (Type the criteria manually)
=SUMIF($A$2:$A$12,"*"&D2&"*",$B$2:$B$12)                 
 (Use a cell reference)

Note: This SUMIF function is not case-sensitive.


Sum values if cell contains specific or partial text with SUMPRODUCT function

The SUMPRODUCT function also can help you to finish this job without using any wildcard. Here, you should wrap the ISNUMBER and SEARCH functions inside a SUMPRODUCT function, the generic syntax is:

=SUMPRODUCT(sum_range *(ISNUMBER(SEARCH(criteria,range))))
  • sum_range: The range of cells with matched numeric values that you want to sum;
  • criteria: The criteria you want to sum values based on. It can be a cell reference or specific text you defined;
  • range: The data range you want to evaluate using the criteria;

Please use any one of the below formulas into a blank cell, and press Enter key to return the result:

=SUMPRODUCT($B$2:$B$12*(ISNUMBER(SEARCH("T-Shirt",$A$2:$A$12))))          (Type the criteria manually)
=SUMPRODUCT($B$2:$B$12*(ISNUMBER(SEARCH(D2,$A$2:$A$12))))                   
(Use a cell reference)


Explanation of this formula:

=SUMPRODUCT($B$2:$B$12*(ISNUMBER(SEARCH("T-Shirt",$A$2:$A$12))))

  • SEARCH("T-Shirt",$A$2:$A$12): The SEARCH function returns the location of the specific text “T-Shirt” from the data range A2:A12, so, you will get an array like this: {5;#VALUE!;#VALUE!;7;#VALUE!;7;#VALUE!;#VALUE!;#VALUE!;#VALUE!;7}.
  • ISNUMBER(SEARCH("T-Shirt",$A$2:$A$12))= ISNUMBER({5;#VALUE!;#VALUE!;7;#VALUE!;7;#VALUE!;#VALUE!;#VALUE!;#VALUE!;7}): This ISNUMBER function is used to test for the numeric values, and returns a new array: {TRUE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE}.
  • $B$2:$B$12*(ISNUMBER(SEARCH("T-Shirt",$A$2:$A$12)))= {347;428;398;430;228;379;412;461;316;420;449}*{TRUE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;TRUE}: To multiply these two arrays, the math operation forces the TRUE and FALSE values to 1s and 0s. So, the multiplication of the two arrays will be like this: {347;428;398;430;228;379;412;461;316;420;449}*{1;0;0;1;0;1;0;0;0;0;1}={347;0;0;430;0;379;0;0;0;0;449}.
  • SUMPRODUCT($B$2:$B$12*(ISNUMBER(SEARCH("T-Shirt",$A$2:$A$12)))) =SUMPRODUCT({347;0;0;430;0;379;0;0;0;0;449}):Finally, the SUMPRODUCT function sums all values in the array to get the result:1605.

Relative function used:

  • SUMIF:
  • The SUMIF function can help to sum cells based on one criterion.
  • SUMPRODUCT:
  • The SUMPRODUCT function can be used to multiply two or more columns or arrays together, and then get the sum of products.
  • ISNUMBER:
  • The Excel ISNUMBER function returns TRUE when a cell contains a number, and FALSE if not.
  • SEARCH:
  • The SEARCH function can help you to find the position of a specific character or substring from the given text string

More articles:

  • Sum Smallest Or Bottom N Values
  • In Excel, it is easy for us to sum a range of cells by using the SUM function. Sometimes, you may need to sum the smallest or bottom 3, 5 or n numbers in a data range as below screenshot shown. In this case, the SUMPRODUCT together with the SMALL function can help you to solve this problem in Excel.
  • Sum Smallest Or Bottom N Values Based On Criteria
  • In previous tutorial, we have discussed how to sum the smallest n values in a data range. In this article, we will perform a further advanced operation – to sum the lowest n values based on one or more criteria in Excel.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.

  • Designed for 1500 work scenarios, helps you solve 80% Excel problems.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
  • Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
  • 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.
Ribbon of Excel (with Kutools for Excel installed)

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.
Screen Shot of Excel (with Office Tab installed)
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations