Smart Systems for Home

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

How to Count Unique Values in Excel Range

· 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 count unique values in an Excel range, the most reliable modern method is the UNIQUE function combined with COUNTA: enter =COUNTA(UNIQUE(A1:A20)) in a blank cell. This spills a list of distinct entries and counts them in one step. On older Excel versions without UNIQUE, use =SUMPRODUCT(1/COUNTIF(A1:A20,A1:A20)) or a helper-column approach. Both methods ignore blanks only if you adjust them, so read the steps below for the exact formula that matches your data.

What You'll Need

  • Excel 365, Excel 2021, or Excel for the web for the UNIQUE function. Older versions (2019 and earlier) need the SUMPRODUCT or helper-column method.
  • A range of data with no merged cells inside it — merged cells break both formulas.
  • A blank cell outside the data range to hold the result.
  • Basic familiarity with entering formulas and dragging fill handles.

Step-by-Step

  1. Select your data range. Click the first cell of your list and note the last cell. For example, if your values sit in A2 through A50, your range is A2:A50. Avoid including the header row unless you want the header counted as a unique value.
  2. Pick a blank output cell. Choose a cell well away from your data, such as D2, so the spilled results from UNIQUE do not overwrite anything.
  3. Enter the UNIQUE + COUNTA formula (Excel 365/2021/web). Type =COUNTA(UNIQUE(A2:A50)) and press Enter. The UNIQUE part returns a list of distinct values; COUNTA counts how many items are in that list. The result is your unique count.
  4. Check the spill. If you entered the formula in D2, Excel will spill the distinct values down column D starting at D2. The single number in the formula cell is the count. If you see a #SPILL! error, something is blocking the spill area — clear the cells below D2 and the error resolves.
  5. Count unique values ignoring blanks. If your range contains empty cells, UNIQUE will include a 0 for the blank, inflating the count. Use =COUNTA(UNIQUE(FILTER(A2:A50,A2:A50<>""))) instead. FILTER removes blanks before UNIQUE runs.
  6. Count unique values with criteria. To count distinct entries only where a second column matches a condition, use =COUNTA(UNIQUE(FILTER(A2:A50,B2:B50="North"))). Replace "North" with your criterion. This counts distinct values in column A where column B equals North.
  7. Use the SUMPRODUCT method on older Excel. In Excel 2019 or earlier, enter =SUMPRODUCT(1/COUNTIF(A2:A50,A2:A50)). This counts each value once by dividing 1 by how many times it appears, then summing. It requires no helper column but does not handle blanks — a blank cell causes a #DIV/0! error.
  8. Use a helper column if SUMPRODUCT errors on blanks. In B2 enter =IF(A2="","",1/COUNTIF($A$2:$A$50,A2)) and fill down to B50. Then sum column B with =SUM(B2:B50). Blanks return an empty string and are ignored by SUM.
  9. Verify the result. Cross-check by selecting the range, opening the Data tab, and using Remove Duplicates on a copy of the data — the number of rows removed plus the rows remaining should equal your original row count, and the remaining rows equal your unique count.

Common Mistakes

  • Including the header row. If A1 contains "Customer" and your data starts at A2, a range of A1:A50 counts the header as a unique value. Start at A2.
  • Forgetting that UNIQUE counts blanks as zero. An empty cell in the range becomes a 0 in the spilled list and adds one to COUNTA. Use FILTER to exclude blanks.
  • Using COUNTA on the whole range instead of the UNIQUE result. =COUNTA(A2:A50) counts non-empty cells, not distinct values. The UNIQUE wrapper is what makes it a unique count.
  • Hard-coding the range without dollar signs in the helper-column method. When you fill down, relative references shift. Use $A$2:$A$50 inside COUNTIF so every row compares against the same range.
  • Case sensitivity. UNIQUE and COUNTIF treat "Apple" and "apple" as the same value by default. If you need case-sensitive counts, use =SUMPRODUCT(--(COUNTIF(A2:A50,A2:A50)=1)) only after normalizing case, or use EXACT in a helper column.
  • Trailing spaces. "North " and "North" are different to Excel. Use TRIM on your data first: =TRIM(A2) in a helper column, then count uniques on the trimmed column.

Tips

  • Convert your range to an Excel Table (Ctrl+T) and use structured references like =COUNTA(UNIQUE(Table1[Customer])). The formula auto-expands as you add rows.
  • To count unique values across multiple columns, stack them with VSTACK in Excel 365: =COUNTA(UNIQUE(VSTACK(A2:A50,B2:B50))).
  • Use =ROWS(UNIQUE(A2:A50)) as an alternative to COUNTA — it counts rows in the spilled array and avoids counting a header if one appears.
  • If you only need the count and not the list, wrap the formula in a single cell and hide the spill by placing it in a column you do not use, or press Ctrl+Shift+Enter in older Excel to force an array formula.
  • For a quick visual check, apply Conditional Formatting > Highlight Cells Rules > Duplicate Values to your range. Unique values stay unhighlighted, giving you a rough count at a glance.

Troubleshooting

  • #NAME? error: Your Excel version does not support UNIQUE. Check File > Account > About Excel. If you see Excel 2019 or earlier, switch to the SUMPRODUCT or helper-column method.
  • #SPILL! error: The cells below your formula are not empty. Clear them or move the formula to a cell with enough blank space beneath it.
  • #DIV/0! error with SUMPRODUCT: Your range contains blank cells. Either restrict the range to the exact data rows or switch to the helper-column method with IF(A2="","",...).
  • Count is one too high: A blank cell is being counted as a unique value. Use the FILTER version of the formula.
  • Count is lower than expected: Values that look different may be identical after Excel ignores case and trailing spaces. Run TRIM and check for hidden characters with CLEAN.
  • Formula returns a list instead of a single number: You used UNIQUE alone. Wrap it in COUNTA or ROWS to get the count.

Frequently Asked Questions

What is the difference between unique and distinct values in Excel?

Unique values appear exactly once in the range; distinct values are all different entries regardless of how many times they appear. UNIQUE returns distinct values by default. To count values that appear only once, use =SUM(--(COUNTIF(A2:A50,A2:A50)=1)).

Can I count unique values without a formula?

Yes. Copy the range to a new location, go to Data > Remove Duplicates, and the remaining row count is your unique count. This is a one-time check, not a live formula.

Does UNIQUE work in Excel for the web?

Yes, UNIQUE and FILTER are available in Excel for the web and in Excel 365 and 2021 desktop apps. They are not available in Excel 2019 or earlier.

How do I count unique values across two columns?

In Excel 365, use =COUNTA(UNIQUE(VSTACK(A2:A50,B2:B50))). In older versions, copy both columns into one helper column and run the SUMPRODUCT method on that column.

Why does my unique count include zero?

A blank cell in the range is treated as 0 by UNIQUE. Wrap the range in FILTER to exclude blanks: =COUNTA(UNIQUE(FILTER(A2:A50,A2:A50<>""))).

Can I count unique values that meet a condition?

Yes, with FILTER inside UNIQUE: =COUNTA(UNIQUE(FILTER(A2:A50,B2:B50="North"))). This counts distinct entries in column A only where column B equals North. Adjust the criterion to match your data.