To sum values based on whether a cell contains specific text, use the SUMIF function combined with asterisks (*) as wildcards. For example, =SUMIF(A1:A10, "*text*", B1:B10) will sum all values in range B1:B10 where the corresponding cell in A1:A10 contains the word "text" anywhere in the cell.

This technique is essential for analyzing data where cells contain multiple pieces of information (e.g., "Office Supplies - Paper" and "Office Supplies - Pens") and you want to aggregate all entries that share a common keyword without needing an exact match for the entire cell.

What You'll Need

  • Microsoft Excel (any version from 2007 to the current Microsoft 365).
  • A dataset containing a column of text labels and a corresponding column of numerical values.
  • Basic familiarity with selecting cell ranges.

Step-by-Step

  1. Organize Your Data: Ensure your data is in two distinct columns. For this guide, assume Column A contains the descriptions (text) and Column B contains the amounts (numbers) you want to sum.
  2. Select Your Result Cell: Click on the empty cell where you want the total sum to appear.
  3. Start the SUMIF Formula: Type =SUMIF( into the cell.
  4. Define the Range: Highlight the range of cells that contains the text you are searching through. For example, click and drag from A2 to A100. After selecting the range, type a comma (,).
  5. Enter the Criteria with Wildcards: This is the most important step. To find a cell that contains a specific word regardless of what comes before or after it, wrap the word in asterisks and double quotes.
    • Example: If you want to sum everything containing the word "Apple", type "*Apple*".
    • The asterisk (*) acts as a placeholder for any number of characters.
    Type a comma (,) after the closing quote.
  6. Define the Sum Range: Highlight the range of cells containing the numbers you want to add up. For example, click and drag from B2 to B100.
  7. Close and Execute: Type a closing parenthesis ) and press Enter.

Common Mistakes

  • Forgetting Quotes: If you type *Apple* without the double quotes, Excel will return an error or treat it as a named range. Text criteria must always be enclosed in quotes.
  • Confusing SUMIF with SUMIFS: SUMIF is for one single condition. If you try to add multiple criteria (e.g., text contains "Apple" AND date is "January"), you must use the SUMIFS function, which has a different syntax (the sum range comes first).
  • Mismatched Range Sizes: The "Range" (where you look for text) and the "Sum Range" (where the numbers are) must be the exact same size. If the first range is A2:A100 and the second is B2:B50, the formula may return inaccurate results or an error.
  • Hidden Spaces: While wildcards usually handle this, trailing spaces in your criteria (e.g., "*Apple "*) will force Excel to look for a space after the word, which might exclude cells that end exactly with "Apple".

Tips

  • Cell Referencing: Instead of typing the text directly into the formula, you can refer to another cell. If cell D1 contains the word "Apple", your formula would look like: =SUMIF(A2:A100, "*" & D1 & "*", B2:B100). The ampersand (&) joins the wildcards to the cell value.
  • Case Sensitivity: Note that SUMIF is not case-sensitive. Searching for "*APPLE*" will also sum cells containing "apple" or "Apple".
  • Start/End Specificity: If you only want to sum cells that start with a specific word, place the asterisk only at the end: "Apple*". If you only want cells that end with a word, place it only at the start: "*Apple".

Troubleshooting

If your formula is returning 0 or an incorrect value, try these steps in order:

  1. Check Number Formatting: Ensure the numbers in your sum range are actually formatted as "Number" or "Currency" and not as "Text". If you see a small green triangle in the corner of the cell, the number is likely stored as text and will be ignored by SUMIF. Select the cells and convert them to numbers.
  2. Verify Wildcard Placement: Double-check that you have an asterisk on both sides of the text if the keyword appears in the middle of the string.
  3. Check for Circular References: Ensure your result cell is not located within the ranges you are summing, as this creates a circular reference error.
  4. Clear Extra Spaces: Use the =TRIM() function on your data columns to remove any accidental leading or trailing spaces that might be interfering with the match.

Frequently Asked Questions

Can I sum cells that contain any text at all, regardless of the specific word?

Yes. Use a single asterisk as your criteria: =SUMIF(A2:A100, "*", B2:B100). This will sum all rows where the cell in the first range contains any text string.

How do I sum cells that do NOT contain specific text?

Use the "not equal to" operator (<>) inside the quotes. For example: =SUMIF(A2:A100, "<>*Apple*", B2:B100) will sum everything except cells containing "Apple".

Does this work for summing based on a partial number?

No. Wildcards only work with text strings. If your "ID numbers" are stored as numbers, the asterisk will not work. You would first need to convert those numbers to text or use a different approach like the RIGHT or LEFT functions within a SUMPRODUCT formula.

Can I use this to sum based on two different text keywords?

SUMIF only handles one condition. To sum cells containing "Apple" OR "Orange", you can add two SUMIF formulas together: =SUMIF(A2:A100, "*Apple*", B2:B100) + SUMIF(A2:A100, "*Orange*", B2:B100). Be careful: if a cell contains both words, it will be counted twice.

What if I want to sum based on multiple specific words in the same cell?

For "AND" logic (cells containing both "Apple" AND "Red"), use the SUMIFS function: =SUMIFS(B2:B100, A2:A100, "*Apple*", A2:A100, "*Red*").