Count Repeated Code Occurrences in Excel with COUNTIF
Question details
Count the number of occurrences of every code in a column and display each code's count in a second column.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A large code list contains duplicate values, and the user needs a formula that returns the total frequency for each row's code.
- Observed behavior
- Each code should receive a count showing how many times that same value appears in the full code range.
Confirm that the code values are in one continuous column and that the count column is empty. Adjust the example range A2:A200 to include the first and last cells in your actual list.
Use COUNTIF and fill the formula down the count column
Use this reliable method when each row needs a count for its corresponding code, regardless of how many unique codes are in the list.
The COUNTIF criteria range is locked with dollar signs so it remains unchanged as the formula is copied down. The criteria cell, A2, changes to match each row's code.
In the first count cell, such as B2, enter =COUNTIF($A$2:$A$200,A2), where A2:A200 is the full code list.
Press Enter to show the number of times the code in A2 appears in A2:A200.
Select B2, then drag the fill handle at the lower-right corner of the cell down through the last row next to your codes.

Use a named range for a clearer COUNTIF formula
Use this option when you want the formula to be easier to read or when the same code list is used in several formulas.
Count codes with a dynamic array formula in Microsoft 365
Use this only in Microsoft 365 when you want the count results to spill automatically into adjacent rows.
Count Repeated Codes in WPS Spreadsheets with COUNTIF
WPS Spreadsheets lets you count repeated codes with the familiar COUNTIF function. Enter one formula beside your code list, then fill it down to calculate the frequency of every value in a large column.
- 1. Open the worksheet in WPS Spreadsheets: Open your Excel workbook in WPS Office and select the worksheet containing the code column.
- 2. Add the COUNTIF formula: Click the first cell in the count column, such as B2, and enter =COUNTIF($A$2:$A$200,A2).
- 3. Calculate the first count: Press Enter to count the occurrences of the code in A2 across the full range.
- 4. Fill the formula down: Select B2 and drag its fill handle down to the last row beside the code list.

Frequently Asked Questions
How do I count each duplicate code in Excel?
In the first result cell, enter =COUNTIF($A$2:$A$200,A2), then copy or drag the formula down. Replace A2:A200 with the complete range containing your codes.
Why are dollar signs used in the COUNTIF range?
The dollar signs lock the range. When you fill the formula down, $A$2:$A$200 stays fixed while the criteria reference changes from A2 to A3, A4, and so on.
Does COUNTIF work when there are more than 100 unique values?
Yes. COUNTIF counts matches in the specified range and is not limited by the number of unique values. Use a range that includes all rows of your list.
Can I use a named range instead of cell references in COUNTIF?
Yes. After naming the code list CodeRange through Formulas > Define Name, use =COUNTIF(CodeRange,A2) and fill the formula down.
How can I count duplicates in WPS Spreadsheets?
In WPS Spreadsheets, click the first output cell and enter =COUNTIF($A$2:$A$200,A2). Press Enter, then drag the fill handle down to apply the formula to the rest of the rows.




