Excel Supreme

Excel track · Exercise 53 of 86 Paid

Wildcards in text criteria

Write a wildcard criterion in COUNTIF and reuse the same pattern in SUMIF.

Intermediate

Regions and amounts beside codes that share one pattern

Read-only data · screen 1 of 2 · answer in D2

In D2, count the North rows with a wildcard criterion.

ABCD
1CodeRegionAmountAnswer
2AN-1042North120
3BO-2299South80
4CY-3140North200
5DE-4471North60

Download this grid (.xlsx) Two tabs: the grid you see, and the answer.

D2

What it does

A criterion is the text that tells COUNTIF or SUMIF which rows count, and two marks inside it act as wildcards. A question mark stands for exactly one character, a star for any run of them including none. Quoted, they turn a plain criterion into a pattern.

On this sheet the region column holds whole words, so Nor* counts the three North rows and N* counts the same three. The code column is where patterns do real work. Every code is two letters, a hyphen and four digits, so ??-* matches all four, and the amounts come to 460.

The criterion always travels in quotes. Without them Excel reads Nor as a name and no count comes back. COUNTIF and SUMIF read criteria the same way, so one pattern serves both.

Syntax

In a criterion, ? matches one character and * matches any run of them

Worked example

On Regions and amounts beside codes that share one pattern, =COUNTIF(B2:B5,"Nor*") returns 3.

=COUNTIF(B2:B5,"Nor*")

Common errors

Error codes for ? and * inside a criteria string, and the same pattern driving a count and a sum
ErrorWhat it means and how to fix it
#VALUE!The criterion cannot be read as text or as a comparison, usually because its quotes are unbalanced.
#REF!A range points at rows that no longer exist after a column was deleted.
Wrong countCOUNTIF(B2:B5,"N") matches nothing and returns 0.

At work

Counting or totalling the rows whose code or name fits one pattern.