Function Problems

How to Number Duplicate IDs Sequentially Using COUNTIF in Excel

Chanuka GeekiyanageChanuka Geekiyanage Nov 11, 2026 868 views

Question details

The user needs to assign sequential occurrence numbers to repeated IDs in an Excel column.

How to Number Duplicate IDs Sequentially Using COUNTIF in Excel
Product
Excel
Device & OS
not provided
Scenario
Tracking the occurrence order of duplicate records or IDs in a dataset.
Observed behavior
The first instance of an ID is assigned 1, the second instance 2, and subsequent instances continue sequentially.
Before you start

Ensure your data does not have empty rows within the target column, and identify the starting cell of your ID list.

Solution 1Recommended

Use an Expanding Range with the COUNTIF Function

The most efficient way to number duplicates sequentially is by using a dynamic expanding range inside the COUNTIF function.

This standard method uses a mix of absolute and relative cell references. The formula anchors the starting point of the range but allows the end point to stretch as it moves down the column.

1
Select the target cell

Select the cell adjacent to the first ID in your list. For example, click on cell B2 if your IDs are located in column A starting at A2.

2
Enter the formula

Type the formula =COUNTIF($A$2:A2, A2) into the formula bar and press Enter. This will return '1' for the very first occurrence.

3
Fill the formula down

Click and drag the fill handle (the small square at the bottom-right of the cell) down to copy the formula to the rest of the column.

Use an Expanding Range with the COUNTIF Function
How it works: The absolute reference ($A$2) locks the start of the range, while the relative reference (A2) expands as you drag the formula down, counting only the instances up to the current row.
Data Processing Made Easy

Easily Sequence and Manage Data with WPS Spreadsheet

WPS Spreadsheet fully supports standard formulas like COUNTIF and dynamic arrays, allowing you to sequence duplicate IDs effortlessly. It offers a user-friendly interface highly compatible with Excel formats.

  1. 1. Open your file: Launch WPS Spreadsheet and open the document containing your dataset.
  2. 2. Enter the formula: Click on the cell next to your first ID and type =COUNTIF($A$2:A2, A2).
  3. 3. Auto-fill the column: Hover over the bottom-right corner of the cell and double-click the fill handle to automatically apply the formula to the entire column.
Fully compatible with Microsoft Excel formulas like COUNTIF and LETLightweight and fast, even when processing large datasetsFree built-in data analysis and deduplication toolsCross-platform support for Windows, Mac, Linux, and Mobile
microsoft office alternative - wps office

Frequently Asked Questions

Why does my COUNTIF formula return the total count instead of a sequential number?

This usually happens if you lock both sides of the range (e.g., $A$2:$A$100). Make sure you only lock the starting cell ($A$2) and leave the ending cell as a relative reference (A2) so the range expands as you drag it down.

Can I restart the numbering if the ID changes?

Yes. The expanding COUNTIF formula inherently restarts at 1 for any new ID it encounters in the list, as it only counts instances of that specific ID appearing up to the current row.

How do I highlight the second and subsequent duplicates using this method?

You can use this same logic in Conditional Formatting. Select your data range, create a new rule using a formula, and enter =COUNTIF($A$2:A2, A2)>1. Apply a format like a red fill to highlight repeat instances.

Does this method work if the data is not sorted?

Yes, the expanding COUNTIF method works perfectly on unsorted data. It will identify and sequence occurrences in the exact chronological order they appear from top to bottom.