This is an annoyingly long introduction, but the context is important, sorry!
If you try to count very long numbers (16+ digits) in a range with COUNTIF, you may see incorrect results, due to a bug in how certain functions handle long numbers, even when those numbers are stored as text. Consider the screen below. All counts in column D are incorrect —although each number in column B is unique, the count returned by COUNTIF suggests these numbers are duplicates.
This problem is related to how Excel handles numbers. Excel can only handle 15 significant digits, and if you enter a number with more than 15 digits in Excel, you'll see the trailing digits silently converted to zero. The counting problem mentioned above arises from this limit.
Normally, you can avoid this limit by entering long numbers as text, either by starting the number with a single quote ('999999999999999999) or by formatting the cell(s) as Text before entering. As long as you don't need to perform math operations on a number, this is a good solution, and it lets you enter extra long numbers for things like like credit card numbers and serial numbers without losing any numbers.
However, if you try to use COUNTIF to count a number with more than 15 digits (even when stored as text) you may see unreliable results. This happens because COUNTIF internally converts the long value back to a number at some point during processing, triggering the 15 digit limit described above. Without all digits present, some numbers may be counted like duplicates when counted with COUNTIF.
One solution is to replace the COUNTIF formula with a formula that uses SUM or SUMPRODUCT. In the example shown, the formula in E5 looks like this:
The SUMPRODUCT function multiplies ranges or arrays together and returns the sum of products. This sounds boring, but SUMPRODUCT is an incredibly versatile function that can be used to count and sum like COUNTIFS or SUMIFS, but with more...
COUNTIF is a function to count cells that meet a single criteria. COUNTIF can be used to count cells with dates, numbers, and text that match specific criteria. The COUNTIF function supports logical operators (>,...
Learn Excel formulas and functions with concise, clear videos. Master absolute/relative addresses, dates, text, named ranges, and tools for troubleshooting. Each video comes with a practice worksheet and audio transcript. Instant access and complete 100% guarantee. Start today!