When you work with a worksheet with many different numbers, you may need to count the number of cells that meet a certain criterion. In this article, we will figure out the numbers starting with a digit, and please check here to count cells ending with a digit.
Example: You are working with a dataset with the product in column A, the date a product is sold in column B, and the sale amount in column C.
Formula: How many cells start with 5?
=SUMPRODUCT(–(LEFT(C2:C12,1)="5"))
=SUMPRODUCT((LEFT(C2:C12,1)="5")*1)
- Step 1: (–(LEFT(C2:C12,1)="5")): Check the first digit and see if the result is equal to 5;
- Step 2: The double hyphen (or times 1) is to convert true into one and false into zero;
- The SUMPRODUCT function returns the sum of the products of the new array.
The result returns 3, so three numbers in column C start with "5".
Notes: The LEFT Function
Formula:
=LEFT(text, [num_chars])
Explanations:
– Text is required, and the text string contains the characters you want to extract.
– Num_chars is optional and specifies the number of characters you want LEFT to extract.