How to Generate Automatic Serial Numbers Based on an Adjacent Excel Column
Question details
The user wants to automatically generate sequential serial numbers in column A based on the populated rows in column B, which updates dynamically from drop-down selections and array formulas.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Creating a dynamic numbered list that automatically expands or contracts when the adjacent source data changes.
- Observed behavior
- The user needs a formula setup that dynamically detects the variable number of non-empty rows in column B and populates the exact corresponding amount of serial numbers in column A.
Determine whether your adjacent data column is populated using a modern spilled dynamic array formula or standard individual cell data, as this dictates the best formula to use.
Use Dynamic Array Formulas (SEQUENCE)
This is the most efficient method if your adjacent column contains a spilled dynamic array formula.
By utilizing the SEQUENCE function combined with an IF statement, your serial numbers will automatically spill down the exact number of rows as the target array. The '#' symbol refers to the entire spilled array range starting from the referenced cell.
Click on cell A2, or whichever cell you want your serial numbers to start in.
Type the formula `=IF(B2#<>"",SEQUENCE(ROWS(B2#)),"")` into the formula bar. Replace 'B2' with the starting cell of your adjacent dynamic array.
Press Enter. The serial numbers will automatically populate and expand or contract whenever the drop-down selection changes the array size in column B.

Use the Traditional COUNTIF Method
A highly compatible solution that works across all versions of Excel and WPS Spreadsheet, ideal for standard cell entries and Excel Tables.
Auto-Number Dynamic Rows Easily with WPS Spreadsheet
WPS Spreadsheet fully supports advanced dynamic arrays and functions like SEQUENCE, allowing you to create auto-adjusting serial numbers seamlessly while maintaining complete compatibility with your existing Excel files.
- 1. Open your file in WPS: Launch WPS Spreadsheet and open your workbook containing the dynamic drop-down lists.
- 2. Select the serial number column: Click the first cell in column A where the numbering should begin.
- 3. Insert the dynamic formula: Type `=IF(B2#<>"",SEQUENCE(ROWS(B2#)),"")` and press Enter.
- 4. Watch the data update automatically: Change your drop-down selection to verify that the serial numbers adjust perfectly to match the number of populated rows in column B.

Frequently Asked Questions
Why is my SEQUENCE formula returning a #NAME? error?
A #NAME? error usually means your version of Excel or your spreadsheet software does not support dynamic array functions like SEQUENCE. If this happens, use the alternative `=IF(B2<>"",COUNTIF($B$2:B2,"<>"),"")` formula method instead.
How can I handle blank rows in the middle of my data?
If your data in column B contains blank rows but you want the serial numbers to continue sequentially without skipping numbers, the COUNTIF method `=IF(B2<>"",COUNTIF($B$2:B2,"<>"),"")` works perfectly, as it only increments the count when it encounters non-blank cells.
What does the '#' symbol mean in the formula?
The '#' symbol is the spilled range operator. When placed after a cell reference (like B2#), it tells the spreadsheet software to reference the entire dynamic array range that originates from that cell, rather than just the single cell.




