Sheet Clinic

Google Sheets COUNTIF contains text: wildcards and IF

To count cells that contain text, put an asterisk on each side of the keyword, as in "*late*". Then an if cell contains Yes or No for each row.

Sheet Clinic editorsPublished
F2=COUNTIF(B2:B11, "*"&E2&"*")

Before as you see it

BCDEF
1NoteHas keyword?KeywordNotes with keyword
2Delivery came late againNolate1
3Great service, friendly driverNo
4Order was late and the box was damagedNo
5lateNo
6Loved the chocolate muffinsNo
7Late by two daysNo
8Driver was politeNo
9Can you deliver on Sundays?No
10Wrong item, please call meNo
11Running late is fine, food was hotNo

What changed

  1. F2 criterion wrapped in "*"
  2. C2:C11 use COUNTIF inside IF

After wildcards added

BCDEF
1NoteHas keyword?KeywordNotes with keyword
2Delivery came late againYeslate6
3Great service, friendly driverNo
4Order was late and the box was damagedYes
5lateYes
6Loved the chocolate muffinsYes
7Late by two daysYes
8Driver was politeNo
9Can you deliver on Sundays?No
10Wrong item, please call meNo
11Running late is fine, food was hotYes
Figure 1. The same ten notes before and after. F2 goes from 1 to 6, and column C finds the keyword in six rows.

To count cells that contain a word in Google Sheets, put an asterisk on each side of it in the COUNTIF criterion, as in =COUNTIF(B2:B11, "*late*"). Without the asterisks, COUNTIF only counts cells whose entire text is the keyword. With the word in its own cell, E2, the criterion becomes "*"&E2&"*". In this sheet, that change in F2 takes the count from 1 to 6.

This sheet gives three answers to one question: 1, 6 or 5. The question is how many of the ten customer notes in B2:B11 mention late, and the answer depends on which formula asks it. All three formulas read the same notes and the same keyword.

Method and formulaReturned, and the notes counted
Plain keyword
=COUNTIF(B2:B11, E2)
1 (row 5 only)
Wildcards
=COUNTIF(B2:B11, "*"&E2&"*")
6 (rows 2, 4, 5, 6, 7, 11)
Whole word
=SUMPRODUCT(--REGEXMATCH(B2:B11, "(?i)\blate\b"))
5 (rows 2, 4, 5, 7, 11)

Read by eye, five of the notes use the word, from Jessica's delivery in row 2 to Josh's note in row 11. The plain COUNTIF on the Broken tab finds one of them. The wildcard version on the Fixed tab finds six, one more than the eye count, and the REGEXMATCH version on the More cases tab lands on five. A Yes or No for each row takes the same wildcards, with COUNTIF pointed at a single cell inside IF: =IF(COUNTIF(B2, "*"&$E$2&"*"), "Yes", "No").

COUNTIF with a plain keyword matches the whole cell

The 1 in F2 on the Broken tab comes from row 5. Given a plain word, COUNTIF compares it with the entire cell, so a note counts only when late is all it says. Matthew's note is that one word. Jessica's "Delivery came late again" has the word in the middle and fails the comparison, along with every other note that uses late in a sentence.

Exact matching suits a column where each cell holds one value, like a status code, and counting two such codes at once is covered in COUNTIF with OR. Feedback notes are full sentences, so the plain criterion skips four of the five notes that use the word.

Counting cells that contain text: an asterisk on each side of the keyword

The Fixed tab changes F2 to =COUNTIF(B2:B11, "*"&E2&"*"). The ampersands join an asterisk to each side of whatever sits in E2, so COUNTIF receives *late*. Google's COUNTIF help page lists two wildcards a criterion can hold: ? for any single character and * for zero or more characters in a row. With one on each side, any text may come before late and any text may follow it, and "any" includes nothing at all. That is why Matthew's one-word note still counts.

F2 on the Fixed tab returned 6. Because the formula adds the asterisks, E2 stays a plain word, and typing a different keyword there changes what gets counted without touching the formula. In a sheet of your own, the range B2:B11 and the keyword cell are the two parts to change. To skip the keyword cell, put the whole pattern inside one pair of quotes, =COUNTIF(B2:B11, "*late*"). That version sits in F2 of the More cases tab and also returned 6. Either way the asterisks go inside the criterion. The formula itself still starts with an equals sign.

The Fixed tab with F2 selected. The formula bar shows =COUNTIF(B2:B11, "*"&E2&"*") and F2 shows 6. Column C shows Yes in rows 2, 4, 5, 6, 7 and 11.
Figure 2. The Fixed tab. F2 counts six notes, and column C marks the same six rows.
Input10 notes in B2:B11, keyword late in E2
Formula=COUNTIF(B2:B11, "*"&E2&"*")
Expected6
Sheets returned6 Matches expected
Checked2026-11-11, free personal account

An "if cell contains" Yes or No per row, with COUNTIF inside IF

Column C asks the same question one row at a time and answers Yes or No. On the Broken tab every row runs =IF(B2="*"&$E$2&"*", "Yes", "No"), with the asterisks already in place, and all ten rows say No. That includes row 5, where the note is the keyword itself.

An equals sign does no pattern matching. In B5="*"&$E$2&"*" it checks whether Matthew's note is literally an asterisk, the letters l, a, t, e, and another asterisk. The note is just the four letters, so C5 returns No.

The Broken tab with C5 selected. The formula bar shows =IF(B5="*"&$E$2&"*", "Yes", "No"). B5 holds late and C5 shows No. Every cell in C2:C11 shows No.
Figure 3. C5 on the Broken tab. The note in B5 is the keyword itself, and the IF still says No.

The Fixed tab hands the matching to COUNTIF and gives it a range of one cell. C2 holds =IF(COUNTIF(B2, "*"&$E$2&"*"), "Yes", "No"). Counting a single cell can only give 1 or 0, and IF treats 1 as true and 0 as false. Copied down to C11, the column says Yes on six rows and No on four, and the six are the notes F2 counts.

Keep the dollar signs in $E$2. They pin every copy of the formula to the keyword cell. Without them, the copy in C3 would read E3, and E3 is empty.

Whole-word matches with REGEXMATCH, so chocolate stops counting as late

Six is one more than the five notes that use the word. The extra one is row 6, where Sarah loved the chocolate muffins. Chocolate ends in l-a-t-e, and *late* has no idea where a word starts.

For a whole-word count, F7 on the More cases tab holds =SUMPRODUCT(--REGEXMATCH(B2:B11, "(?i)\blate\b")), and it returned 5. REGEXMATCH tests each note against a regular expression and gives back TRUE or FALSE. The double minus turns those into 1s and 0s for SUMPRODUCT to add up. In the pattern, \b marks a word boundary, so the letters right before late in chocolate block the match. The (?i) at the front turns off case matching, which keeps David's capitalized Late in the count. The REGEXMATCH help page says Sheets follows RE2 syntax for these patterns.

Column C on the More cases tab is the per-row version, =IF(REGEXMATCH(B2, "(?i)\blate\b"), "Yes", "No"). Against column C of the Fixed tab, one row differs. Sarah's chocolate note says No there.

The More cases tab with F7 selected. The formula bar shows =SUMPRODUCT(--REGEXMATCH(B2:B11, "(?i)\blate\b")) and F7 shows 5. Column C, headed Whole word?, shows No in row 6 next to Loved the chocolate muffins.
Figure 4. The More cases tab with F7 selected. The whole-word count returns 5, and the Whole word? column says No next to the chocolate note in row 6. F2:F9 hold eight counts on the same notes, with each formula written out in column G.

Capital letters, "?" and "~" in a COUNTIF criterion

The rest of the More cases tab tries other patterns on the same ten notes.

Criterion in COUNTIF(B2:B11, ...)MatchesReturned
"*late*"late anywhere in the note6
"*Late*"the same, typed with a capital L6
"late*"notes that begin with late2
"*?*"any note with at least one character10
"*~?*"notes containing a question mark1
"<>*late*"notes without late anywhere4

The capital L changed nothing, and the COUNTIF help page says outright that COUNTIF is not case sensitive. When case does matter, drop (?i) from the regular expression. =SUMPRODUCT(--REGEXMATCH(B2:B11, "Late")) returned 1, for David's note.

Inside a criterion, ? stands for any one character, so "*?*" matched all 10 notes. A tilde in front, ~?, makes it a literal question mark, and the count fell to 1, Chris asking about Sundays. Per the same help page, a tilde does the same job for a literal asterisk, and two tildes match one tilde.

Trying the wildcard COUNTIF and the IF version on the Try it yourself tab

Try it yourself is a copy of the Broken tab, with 1 in F2 and No all the way down column C. Replace F2 with =COUNTIF(B2:B11, "*"&E2&"*"). Then replace C2 with =IF(COUNTIF(B2, "*"&$E$2&"*"), "Yes", "No") and drag the small square at the corner of C2 down to C11. F2 should read 6, and column C should match the Fixed tab row for row.

If chocolate should not count in your own notes, use the REGEXMATCH formulas from the More cases tab in those two cells instead. Their pattern has late typed into it rather than a reference to E2, so a new keyword means editing the pattern.

A ? or * typed into E2 passes through the "*"&E2&"*" wrapper and acts as a wildcard there too. To count a literal one, type it into E2 with a tilde in front.

Take-home copy. Four tabs: Broken (as you see it), Fixed, Try it yourself, More cases. It opens as a copy in your own Drive.

Copy the sheet