Sub topic 8
Driving criteria from cells
Typing "West" into a formula works, but it means editing the formula every time you want a different region. A better design keeps the conditions in cells and has the formula read them. You change one cell and every total updates.
This chapter assumes you can already write a basic SUMIFS, COUNTIFS, or AVERAGEIFS formula and know the difference between relative and absolute references. It uses the sample sales sheet from earlier chapters: headers in row 1, Date in column A, Region in B, Product in C, Amount in D, and Notes in E.
Replacing a literal with a cell reference
Suppose cell G1 contains the text West. These two formulas return the same result:
=SUMIFS(D2:D100, B2:B100, "West")
=SUMIFS(D2:D100, B2:B100, G1)Excel reads the contents of G1 and uses them as the criterion. A cell reference works in any criteria slot of SUMIFS, COUNTIFS, and AVERAGEIFS. With the four sample rows, both formulas return 1510 (1200 + 310).
A typical control panel puts each condition in its own labeled cell:
| Cell | Label | Example value |
|---|---|---|
| G1 | Region | West |
| G2 | Minimum amount | 500 |
| G3 | Start date | 2025-01-01 |
| G4 | End date | 2025-01-31 |
Labels in column F and inputs in column G make it clear which cell controls which condition.
Adding an operator with &
A cell holding 500 gives an exact-match criterion, which means Amount equals 500. To mean "at least 500", the criterion needs the operator as well. The criterion is a text string, so you build it by joining the operator and the cell value with &:
=SUMIFS(D2:D100, B2:B100, G1, D2:D100, ">=" & G2)If G2 holds 500, Excel evaluates ">=" & G2 to the string ">=500" before SUMIFS sees it. Using the sample rows, this formula sums West rows with Amount of at least 500, which gives 1200.
The same pattern works for every operator:
| Goal | Criteria argument |
|---|---|
| Equal to G2 | `G2` |
| Greater than G2 | `">" & G2` |
| At most G2 | `"<=" & G2` |
| Not equal to G2 | `"<>" & G2` |
The operator must sit inside quotes. Writing >=G2 without quotes is a formula error.
Letting the cell hold the whole criterion
You can also type the operator into the input cell. If G2 contains the text >=500, then plain G2 works as the criterion:
=SUMIFS(D2:D100, D2:D100, G2)This is flexible, because the user can type <100 or <>300 without touching the formula. It is also easier to break, because a typo in the cell silently changes the meaning. Use ">=" & G2 when the cell should hold only a number. Use the whole-criterion style when the user needs to choose the operator.
Dates from cells
Dates are numbers underneath. When you join a date cell to an operator, Excel inserts the date's serial number, and that comparison works correctly against real date cells:
=SUMIFS(D2:D100, A2:A100, ">=" & G3, A2:A100, "<=" & G4)Here G3 is the start date and G4 is the end date, both inclusive. If your dates carry a time of day, a <= test on the end date drops rows later than midnight on that day. In that case, use an exclusive upper bound one day after the end date:
=SUMIFS(D2:D100, A2:A100, ">=" & G3, A2:A100, "<" & (G4 + 1))With the sample data, G3 = 2025-01-01 and G4 = 2025-01-31 give 1500 (1200 + 300).
Partial matches built from a cell
Wildcards are text, so you can join them to a cell value the same way you join operators:
=COUNTIFS(C2:C100, G5 & "*")
=COUNTIFS(C2:C100, "*" & G5 & "*")The first formula counts products that start with the text in G5. The second counts products that contain it anywhere. If G5 holds Lap, both count the Laptop rows.
Dropdowns keep inputs clean
A criterion cell is only as reliable as what users type into it. Add a data validation list to G1 that points at your list of regions. The user then picks West from a dropdown and cannot enter Wset by mistake.
Common problems
A blank criterion cell is treated as zero
If G1 is empty, SUMIFS does not treat it as "any region". Excel reads a reference to an empty cell as the value 0, so the formula looks for cells equal to 0 and usually returns 0. If you want blank inputs to mean "no filter", you need a different approach. One option is a wildcard fallback such as IF(G1="", "*", G1), which matches any text value. Note that * does not match blank cells or numbers.
=SUMIFS(D2:D100, B2:B100, IF(G1="", "*", G1))Invisible differences in the input
A trailing space in the input ("West ") will not match West. Numbers stored as text in the input cell can also fail to match numeric data. If a formula returns 0 and you expect a result, check the input cell first. Compare LEN(G1) with the length you expect.
Copying the formula
When you copy a formula that reads G1, a relative G1 shifts to G2, G3, and so on. Use $G$1 when every copy should read the same input cell. Lock the data ranges too, as in $D$2:$D$100. Mixing the anchors so one formula fills a whole grid is covered in a later chapter.
Wildcard characters in the input
If the input cell itself contains * or ?, Excel treats them as wildcards. To match a literal asterisk, put a tilde before it in the criterion (~*).
Summary of the pattern
- Put each condition in its own input cell with a label.
- Pass the cell directly for an exact match.
- Join an operator or wildcard to it with
&for anything else. - Anchor the input references with
$if you will copy the formula. - Check for blanks, stray spaces, and text-formatted numbers when results look wrong.
Exercise
G1 contains East and G2 contains 250. Write a formula that sums Amount (D2:D100) for rows whose Region (B2:B100) matches G1 and whose Amount is at least G2. What does it return for the four sample rows?
Show answer
=SUMIFS(D2:D100, B2:B100, G1, D2:D100, ">=" & G2). Only the East row (Monitor, 300) qualifies, so the result is 300.
Exercise
G5 contains the text top. Write a formula that counts rows whose Product (C2:C100) contains that text anywhere. Why does the criterion need quotes around the asterisks?
Show answer
=COUNTIFS(C2:C100, "" & G5 & ""). The wildcards are text, so they must be quoted and joined to the cell value with &. Without quotes Excel would read * as a multiplication operator and the formula would fail.