How to Create Sequential IDs That Stay the Same After Sorting in Excel
Question details
The user needs to generate sequential IDs for records that remain constant even after sorting the table, avoiding dynamic changes caused by formulas.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Assigning unique or sequential identifiers to rows based on matching records before sorting the dataset.
- Observed behavior
- Sequential numbers generated by COUNTIFS formulas change dynamically when the table is sorted, and structured references or blank rows cause unexpected numbering.
Ensure your dataset is completely filled out without unexpected blank rows, as blanks can interfere with the counting logic of your sequential formulas.
Convert Dynamic COUNTIFS Formulas to Static Values
The most reliable way to prevent sequential IDs from changing during a sort is to convert the formula results into permanent static values.
When using formulas like COUNTIFS to generate sequence numbers, Excel continuously recalculates them based on their current row position. By pasting the calculated results as values, you break the formula link and lock the IDs permanently.
Enter your running COUNTIFS formula (e.g., =COUNTIFS($A$2:A2,A2)) in the top cell of your target ID column and drag the fill handle down to apply it to all rows.
Select the entire column or range containing the newly generated sequential IDs, right-click the selection, and choose 'Copy'.
Right-click the same selected range again and choose 'Paste as Values' (the clipboard icon displaying '123'). This removes the formulas and leaves only the static numbers.
Now that your IDs are static values rather than formulas, you can sort your Excel table by any column without the sequential IDs changing.

Use Standard Cell References Instead of Table References
If you are working inside an Excel Table, structured table references can cause counting formulas to behave unpredictably when sorting. Switching to absolute and relative cell references resolves this.
Create Permanent Sequential IDs Easily in WPS Spreadsheet
WPS Spreadsheet provides a smooth and highly compatible environment to handle large datasets, complex COUNTIFS formulas, and quick 'Paste as Values' conversions to keep your data perfectly organized.
- 1. Open your workbook: Launch WPS Spreadsheet and open your dataset.
- 2. Enter the sequence formula: Type your running COUNTIFS formula in the ID column to generate the sequence.
- 3. Copy the results: Highlight the calculated IDs, right-click the selection, and click 'Copy'.
- 4. Paste as permanent values: Right-click the selection again, navigate to 'Paste Special', and select 'Paste as Values' to lock the IDs before sorting.

Frequently Asked Questions
Why do my Excel row numbers change when I sort?
If your row numbers or IDs are generated using formulas like ROW() or dynamic COUNTIFS, they automatically recalculate based on their new physical row position after a sort. Converting them to static values prevents this recalculation.
Can I auto-generate sequential IDs without using formulas?
Yes, you can manually type the first two numbers of your sequence (e.g., 1 and 2), highlight both cells, and double-click the small square fill handle in the bottom-right corner to automatically fill the series down the column.
How do I handle blank rows in my COUNTIFS sequence?
You can wrap your COUNTIFS formula in an IF statement to check for blanks first. For example, using =IF(A2="","",COUNTIFS($A$2:A2,A2)) ensures that blank rows do not receive a sequence number and do not disrupt the count.




