Count Text Map Matches & Keep Results Current
In this article
This guide shows you how to count how many times specific words or phrases from a text map (a list of search terms) appear in a body of text, and how to keep those counts updated automatically as your text changes. You’ll learn a practical method using spreadsheet formulas, which works for most text analysis tasks like tracking keywords in customer feedback, monitoring social media mentions, or auditing content for specific phrases. No coding is required, just a spreadsheet application like Google Sheets or Microsoft Excel.
What You'll Need
- A spreadsheet application (Google Sheets, Microsoft Excel, or similar).
- A list of terms you want to count (your “text map”) — for example, a column of keywords or phrases.
- The text you want to search — either pasted into a cell or referenced from another sheet.
- Basic familiarity with spreadsheet formulas (like SUM and LEN).
Step-by-Step
- Prepare your data layout. In a new sheet, put your text map in column A (one term per cell, starting at A2, with A1 as a header like “Term”). Put the text you want to search in a single cell, for example, cell C1 (you can also reference a cell that contains the text, like
=Sheet2!A1). - Create a helper column for counts. In column B, next to each term, you’ll place a formula that counts occurrences. For a simple count of whole words (not substrings), use this formula in B2:
=(LEN($C$1)-LEN(SUBSTITUTE(LOWER($C$1),LOWER(A2),"")))/LEN(A2). This works by measuring the length of the text, removing all instances of the term (case-insensitive), and dividing the difference by the length of the term. This counts overlapping occurrences too (e.g., “cat” in “catcat” counts as 2). - Copy the formula down. Drag the fill handle from B2 down to cover all terms in your text map. Each cell will now show the count for its corresponding term.
- Calculate the total matches. In a cell below your list (e.g., B10), enter
=SUM(B2:B9)(adjust the range to your data). This gives you the total number of matches for all terms combined. - Make it dynamic. Instead of typing text directly into C1, link it to your actual text source. For example, if your text is in another sheet in cell A1, set C1 to
=Sheet2!A1. Now, whenever the source text changes, your counts update automatically. - Handle phrases with spaces. The formula above works for phrases too, but be aware that it counts every occurrence of the exact string, including as part of larger words. If you need whole-word-only matching (e.g., “cat” should not match “catalog”), use a more advanced approach (see Tips).
- Refresh if needed. In Google Sheets, formulas update automatically. In Excel, if you have manual calculation enabled, press F9 to recalculate.
Common Mistakes
- Case sensitivity: The formula uses LOWER() to make it case-insensitive. If you omit LOWER(), you’ll only match exact case, which usually undercounts.
- Counting substrings: The simple formula counts “cat” inside “catalog” as a match. If you need whole-word counts, you must add spaces or use a regex-based approach (see Tips).
- Empty cells: If a term cell is empty, the formula will divide by zero. Ensure your text map has no blank rows, or wrap the formula in IFERROR.
- Overlapping terms: If your text map has similar terms (e.g., “cat” and “catalog”), the counts will overlap. Decide whether that’s acceptable.
- Punctuation: The formula counts punctuation as part of the text. “cat,” will not match “cat” unless you strip punctuation first.
Tips
- For whole-word matching: Use a formula like
=COUNTIF(SPLIT($C$1," "),"*"&A2&"*")in Google Sheets, or in Excel use a more complex array formula with TRIM and SUBSTITUTE. This splits the text into words and counts exact matches. - Use named ranges: Define a named range for your text cell (e.g., “TextToSearch”) to make formulas easier to read.
- Add a total row: Use a SUM formula at the bottom of your count column to see the overall match count at a glance.
- Visualize with conditional formatting: Highlight terms with high counts to spot trends quickly.
- Keep your text map separate: Put your term list on a separate sheet so you can add or remove terms without disturbing the text.
Troubleshooting
- Counts are zero when they shouldn’t be: Check for extra spaces in your text or terms. Use TRIM() on both. Also verify that the text cell reference is correct.
- #DIV/0! error: This happens when a term is empty. Add an IFERROR wrapper:
=IFERROR(your_formula,0). - Counts are too high: This is likely due to substring matching. Switch to a whole-word approach or add word boundaries.
- Results don’t update: In Excel, go to Formulas > Calculation Options and set to Automatic. In Google Sheets, check that you haven’t accidentally set the cell to plain text.
- Formula returns #NAME? This means you’re using a function not available in your spreadsheet (e.g., SPLIT in Excel). Use an alternative method.
- Performance issues with large text: If your text is very long, the formula may slow down. Consider using a script or a dedicated text analysis tool.
Frequently Asked Questions
Q: Can I count multiple terms at once without a helper column?
A: Yes, you can use an array formula like =SUMPRODUCT((LEN($C$1)-LEN(SUBSTITUTE(LOWER($C$1),LOWER(A2:A10),"")))/LEN(A2:A10)) but it’s less readable and harder to debug.
Q: How do I count only whole words, not substrings?
A: In Google Sheets, use =COUNTIF(SPLIT(TRIM($C$1)," "),"*"&A2&"*"). In Excel, use a formula like =SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(" "&TRIM($C$1)&" "," ",REPT(" ",100)),ROW(INDIRECT("1:"&LEN($C$1)+1))*100-99,100)))=A2) which splits by spaces.
Q: Can I count matches in multiple cells (e.g., a column of text)?
A: Yes, adjust the formula to reference a range. For example, =SUMPRODUCT((LEN($C$1:$C$10)-LEN(SUBSTITUTE(LOWER($C$1:$C$10),LOWER(A2),"")))/LEN(A2)) sums across all cells.
Q: How do I make the count case-sensitive?
A: Remove the LOWER() functions from the formula. Then “Cat” and “cat” will be counted separately.
Q: What if my text map has 1000 terms?
A: The formula approach works fine, but you might want to use a pivot table or a script for better performance. Alternatively, use a regex-based tool.
Q: Can I exclude certain words from the count?
A: Yes, you can subtract counts of excluded terms by adding them to your text map with a negative sign, or use a more complex formula with IF conditions.