Calculation Issues

How to Create Sequential IDs That Stay the Same After Sorting in Excel

Rana GarciaRana Garcia Nov 3, 2026 869 views

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.

How to Create Sequential IDs That Stay the Same After Sorting in Excel
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.
Before you start

Ensure your dataset is completely filled out without unexpected blank rows, as blanks can interfere with the counting logic of your sequential formulas.

Solution 1Recommended

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.

1
Apply the sequence formula

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.

2
Copy the generated IDs

Select the entire column or range containing the newly generated sequential IDs, right-click the selection, and choose 'Copy'.

3
Paste as values

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.

4
Sort the data securely

Now that your IDs are static values rather than formulas, you can sort your Excel table by any column without the sequential IDs changing.

Convert Dynamic COUNTIFS Formulas to Static Values
Permanent IDs Secured: Once converted to static values, the IDs are permanently tied to their respective rows, regardless of how many times you filter or sort the dataset.
Efficient Data Management with WPS Office

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. 1. Open your workbook: Launch WPS Spreadsheet and open your dataset.
  2. 2. Enter the sequence formula: Type your running COUNTIFS formula in the ID column to generate the sequence.
  3. 3. Copy the results: Highlight the calculated IDs, right-click the selection, and click 'Copy'.
  4. 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.
Fully compatible with Microsoft Excel formulas and formats (.xlsx).Lightweight and fast, even when calculating thousands of COUNTIFS rows.Intuitive Paste Special menu to quickly lock dynamic IDs into static values.
microsoft office alternative - wps office

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.