You can use the following formula to generate sequence numbers by group in Excel:
This particular formula assumes that the first unique group name is in cell A2 and all remaining groups are also in column A.
The following example shows how to use this formula in practice.
Example: Generate Sequence Numbers by Group in Excel
Suppose we have the following dataset in Excel that contains information about points scored by basketball players on various teams:
Suppose we would like to add a new column that contains sequence numbers by team.
- The first row with a team name of “Mavs” should have a value of 1.
- The second row with a team name of “Mavs” should have a value of 2.
- The third row with a team name of “Mavs” should have a value of 3.
And so on.
The sequence numbers should automatically start over when a new team name is encountered.
We can type the following formula into cell C2 to accomplish this:
We can then drag and fill this formula down to each remaining cell in column C:
Column C now contains sequence numbers by team.
It’s worth noting that this formula also works even if the team names are not in consecutive order.
For example, suppose we have the following dataset in which the team names are scrambled:
We can still use the following formula in cell C2 to generate sequence numbers by team name:
The following screenshot shows how to use this formula in practice:
Notice that the sequence numbers are still correct.
The following tutorials explain how to perform other common tasks in Excel: