Number Groups by Name and Sequence in Excel
Question details
Assign sequential group numbers based on names and changes in a sequence column.
- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Names are in column C, sequence values are in column B, and group numbers should appear in column D.
- Observed behavior
- The group number should restart at 1 when the name changes and increase when the sequence changes from 2 to 1 within the same name.
Arrange rows so each name appears in a contiguous block and the sequence values are numeric 1s and 2s in column B. The example assumes headers are in row 2 and data starts in row 3.
Use IF and AND to Number Sequence Groups
Use this formula to keep the same number within a sequence and increment it when a 2 is followed by a 1.
The formula compares each row with the row above. It resets the number when the name changes; otherwise, it increments only at a 2-to-1 transition.
Select cell D3, type 1, and press Enter.
Select cell D4 and enter =IF(C4<>C3,1,D3+AND(B4=1,B3=2)). Press Enter.
Select D4 and drag its fill handle down through the remaining data rows. Adjust the column and row references if your data is arranged differently.

Number Name and Sequence Groups in WPS Spreadsheets
Use the same IF and AND formula in WPS Spreadsheets to number sequence groups and reset the count when the name changes.
- 1. Open the workbook: Open WPS Spreadsheets, select Open, and choose your workbook.
- 2. Set the first number: With sequence values in column B and names in column C, select D3, type 1, and press Enter.
- 3. Add the formula: Select D4 and enter =IF(C4<>C3,1,D3+AND(B4=1,B3=2)).
- 4. Fill and save: Drag D4's fill handle down to the last data row, then select File > Save.

Frequently Asked Questions
When does the group number increase?
For consecutive rows with the same name in column C, the number increases when column B changes from 2 in the previous row to 1 in the current row.
Why does the number restart when a name appears again?
The formula compares each name only with the preceding row. If the same name appears after a different name, it starts a new block at 1. Arrange matching names together if they should form one block.
How do I adapt the formula if my data starts on another row?
Enter 1 in the output cell of the first data row. In the next row, enter the IF formula using that row's name and sequence cells and the preceding row's cells, then fill it down.
Does this formula number every row?
No. It keeps the current number until the name changes or the sequence changes from 2 to 1. Use a different formula if every row needs its own number.




