Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Formula to Add Numbers Based on Text

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To add numbers in Excel based on a text condition, use the SUMIF function. The syntax is =SUMIF(range, criteria, sum_range), where range is the column containing the text you want to match, criteria is the text (or a cell reference containing it), and sum_range is the column of numbers to add. For example, =SUMIF(A2:A100, "Apple", B2:B100) adds every number in B2:B100 where the matching cell in A2:A100 says "Apple". If you need to match multiple text conditions at once, use SUMIFS instead, which accepts pairs of ranges and criteria. This guide walks through both, plus the mistakes that most often cause a wrong total.

What You'll Need

  • Excel 2016 or later, Excel for Microsoft 365, Excel for Mac, or Excel for the web. The functions described here are available in all of them.
  • A worksheet with at least one column of text labels and one column of numbers. The two columns do not have to be next to each other.
  • Consistent spelling in the text column. SUMIF matches text exactly unless you use wildcards, so "apple" and "Apple" are different criteria.

Step-by-Step

  1. Set up your data in a simple table. Put the text labels in one column (for example A) and the numbers to add in another (for example B). Give each column a header in row 1, such as "Product" and "Amount". Headers are optional for the formula but make ranges easier to read and let you convert the data to an Excel Table later.
  2. Click the cell where you want the total. Pick an empty cell away from the data, for example D2. This is where the result will appear.
  3. Type the SUMIF formula. Start with =SUMIF( and then supply three arguments separated by commas: the range to check, the criteria, and the range to add. A working example is =SUMIF(A2:A100, "Apple", B2:B100). Press Enter and the cell shows the total of all amounts in B2:B100 where the label in column A is exactly "Apple".
  4. Use a cell reference instead of typed text when you want to change the criterion easily. If cell D1 contains the word Apple, write =SUMIF(A2:A100, D1, B2:B100). Changing D1 to another product updates the total without editing the formula. This is the most reliable way to build a small summary block.
  5. Add more than one text condition with SUMIFS. The syntax is =SUMIFS(sum_range, criteria_range1, criteria1, criteria_range2, criteria2, ...). Note that the sum range comes first here, which is the opposite order from SUMIF. For example, =SUMIFS(C2:C100, A2:A100, "Apple", B2:B100, "North") adds values in C where column A says Apple and column B says North. You can add up to 127 range/criteria pairs.
  6. Match partial text with wildcards. The asterisk (*) stands for any number of characters and the question mark (?) stands for exactly one. =SUMIF(A2:A100, "App*", B2:B100) adds every row whose label starts with "App", such as Apple or Application. To find a literal asterisk or question mark, put a tilde before it, as in "~*".
  7. Copy the formula down a summary column. If you list several products in D2:D10 and want a total for each, write the formula once in E2 with absolute references ($A$2:$A$100 and $B$2:$B$100) and drag it down. The dollar signs lock the data ranges so they do not shift as the formula moves.
  8. Check the result against a filtered total. Turn on Filter (Data > Filter), filter the text column to the same word, and select the number column to see its sum in the status bar. If the two totals match, the formula is working. If they do not, the cause is almost always trailing spaces, inconsistent capitalization, or numbers stored as text.

Common Mistakes

  • Mixing up the argument order between SUMIF and SUMIFS. SUMIF puts the criteria range first and the sum range last. SUMIFS puts the sum range first. Swapping them returns a wrong total or zero without any error message.
  • Forgetting quotation marks around typed text. =SUMIF(A2:A100, Apple, B2:B100) is invalid unless Apple is a defined name. Text criteria must be in double quotes, or you must reference a cell that contains the text.
  • Leaving trailing spaces in the text column. "Apple " does not match "Apple". Use TRIM on the source column or clean the data before summing.
  • Assuming SUMIF is case-sensitive. It is not. "apple" and "APPLE" are treated as the same criterion. If case matters, you need a different approach such as SUMPRODUCT with EXACT.
  • Summing numbers stored as text. If the number column was pasted from another system, values may be text and SUMIF will return 0. Convert them with Text to Columns or multiply by 1 in a helper column.
  • Using whole-column references carelessly. A2:A1048576 works but slows large workbooks. Limit ranges to the rows you actually use.

Tips

  • The formula then expands automatically as rows are added.
  • Use a drop-down list (Data > Data Validation) in the criteria cell so users pick from valid labels instead of typing them and creating near-duplicates.
  • For a quick one-off total without writing a formula, filter the list and read the Sum in the status bar at the bottom of the window.
  • If you need to sum based on text in one column but return a total across several number columns, SUMIFS can sum only one column at a time. Add separate formulas for each column, or use SUMPRODUCT for a multi-column total.
  • Name your ranges (Formulas > Define Name) to make formulas readable, for example =SUMIF(Products, "Apple", Amounts).

Troubleshooting

  • The formula returns 0. Check that the criteria text matches exactly, including spaces and capitalization. Confirm the sum range contains real numbers, not text. Select a few cells in the number column and look at the status bar: if it shows Count instead of Sum, the cells are text.
  • The formula returns #VALUE!. A range or criteria argument is malformed, often because a comma is missing or a quote is unclosed. Retype the formula rather than editing it piece by piece.
  • The total is too high. The criteria may be matching more than intended, usually because a wildcard is present or the range includes header rows. Exclude row 1 from the ranges, or use a criteria that cannot match the header text.
  • The total changes when you sort or insert rows. Relative references shift with the data. Use absolute references ($A$2:$A$100) or convert the range to a Table.
  • SUMIFS returns #VALUE! after adding a condition. Every criteria range must be the same size as the sum range. A mismatch in row counts triggers the error.

Frequently Asked Questions

Can SUMIF match text that contains a specific word anywhere in the cell?

Yes. Put asterisks on both sides of the word: =SUMIF(A2:A100, "*apple*", B2:B100). This matches Apple, pineapple, and apple pie alike.

What is the difference between SUMIF and SUMIFS?

SUMIF handles one condition. SUMIFS handles one or more and uses a different argument order, with the sum range first. For a single condition either works, but SUMIFS is the safer habit if you may add conditions later.

Can I add numbers where the text is in a different sheet?

Yes. Reference the other sheet in the range, for example =SUMIF(Sheet2!A2:A100, "Apple", Sheet2!B2:B100). If the sheet name contains spaces, wrap it in single quotes: =SUMIF('Sales Data'!A2:A100, "Apple", 'Sales Data'!B2:B100).

Why does my formula ignore cells that look like they contain the right text?

Invisible characters, non-breaking spaces, or extra spaces copied from web pages are the usual cause. Clean the column with TRIM and CLEAN, then rerun the formula.

Does SUMIF work in Excel for the web and Excel for Mac?

Yes. SUMIF and SUMIFS are standard functions available in Excel for the web, Excel for Mac, and Excel for Windows. Menu labels for inserting functions can differ slightly by version, device, and region.

Can I sum based on text that appears in more than one column?

Not with a single SUMIF. Use SUMIFS with one condition per column, or SUMPRODUCT if the logic is more complex, such as matching any of several labels.