# How to Create a Number Sequence in Excel Based on Criteria

Often, we need to make a number sequence in Excel. Things get a little complicated if we want to do it on the basis of a condition. Do not worry, we have got your back. In this article, we will show 4 quick ways to create a number sequence in Excel based on criteria.

## 4 Handy Approaches to Create a Number Sequence in Excel Based on Criteria

To demonstrate our methods, we have selected a dataset with 3 columns consisting of “Product”, “Brand”, and “Sequence”. Moreover, we will change this a little bit in methods 2 and 3. Our condition will be the brand name and product name. If there is a duplicate product and brand, then we will increment the number sequence. On the other hand, if there is a new entry, then the number sequence will start from 1. In this dataset, notice there are three “Apple” in the Brand column. There are two laptops and one mobile phone for that brand. For the laptop, our number sequence continues, however, for the mobile phone, this counter resets to 1. ### 1. Using COUNTIF Function to Create a Number Sequence in Excel Based on Criteria

In this section, we will use the COUNTIF function to create a number sequence based on a criterion, which is the brand name.

Steps:

• At first, select the cell range D5:D10 and type the following formula.

`=COUNTIF(C\$5:C5,C5)`

This function counts the number of “Apple” in the brand column. The first part of the formula refers to a dynamic range. • Then, press CTRL+ENTER. This will AutoFill the formula to the selected cells.
• Lastly, we can observe that there are:
• Three Samsung mobile phones.
• Two Apple laptops.
• One Lenovo laptop.
• Thus, this formula creates a number sequence based on criteria. ### 2. Inserting Nested IF Function to Create a Number Sequence in Excel Based on Criteria

For the second approach, we will use the IF, AND, COUNTIF, and COUNTIFS functions inside a Nested IF formula to make a number sequence based on conditions.

Steps:

• To begin with, type the following formula in cell D5.

`=IF(AND(C5="Apple",B5="Laptop"),COUNTIF(C\$5:C5,"Apple"),IF(AND(C5="Samsung",B5="Mobile Phone"),COUNTIF(C\$5:C5,"Samsung"),IF(AND(C5="Apple",B5="Mobile Phone"),COUNTIFS(C\$5:C5,"Apple",B\$5:B5,"Mobile Phone"),1)))` • Then, press ENTER.
• Next, use the Fill Handle to AutoFill the formula to the rest of the cells. Formula Breakdown

• There are three combined IF AND functions inside this formula. Whenever the condition is True, the formula executes the COUNTIF portion.
• AND(C5=”Apple”,B5=”Laptop”)
• Output: True.
• At first, this portion checks whether the values from cells C5 and B5 match our defined strings. If matches then it will return True.
• COUNTIF(C\$5:C5,”Apple”)
• Output: 1.
• Secondly, this portion counts the number of Apple brands in the expandable range.
• COUNTIFS(C\$5:C5,”Apple”,B\$5:B5,”Mobile Phone”)
• Output: 0.
• Thirdly, this function counts the number of Apple mobile phones in the expandable range.
• Lastly, we have put 1 at the end of this formula that will be returned if nothing is True.
• Finally, we will achieve our goal of creating a number sequence based on criteria. Moreover, the final step will look like this. ### 3. Applying Combined Formula to Create a Number Sequence Based on Multiple Criteria

In this third approach, we will use the IF, COUNTIFS, and MAX functions to create a combined formula to make a number sequence based on criteria. In this example, we will assign a number sequence for the Date, Time, and Salesperson. Where the different Dates will restart the number sequence.

Steps:

• At first, type the following formula in cell D5.

`=IF(COUNTIFS(\$B\$4:\$B4,\$B5,\$D\$4:\$D4,\$D5)=0,1,MAX(IF((\$B\$4:\$B4=\$B5)*(\$D\$4:\$D4=\$D5),\$E\$4:\$E4,0)+IF(COUNTIFS(\$B\$4:\$B4,\$B5,\$D\$4:\$D4,\$D5,\$C\$4:\$C4,\$C5)>0,0,1)))` • Next, press ENTER and AutoFill the formula. Formula Breakdown

• Firstly, there are two COUNTIFS functions inside this formula. Let us look at them first.
• The first one is → COUNTIFS(\$B\$4:\$B4,\$B5,\$D\$4:\$D4,\$D5)
• Output: 0.
• This function counts the dynamic range with the same time and same salesperson.
• The second one is → COUNTIFS(\$B\$4:\$B4,\$B5,\$D\$4:\$D4,\$D5,\$C\$4:\$C4,\$C5)
• Output: 0.
• Again we get a zero. This time the formula counts the dynamic range for columns B, C, and D.
• (\$B\$4:\$B4=\$B5)*(\$D\$4:\$D4=\$D5)
• Output: 0.
• Here 1 means True and 0 means False. It has given us the False value.
• Then, our formula reduces to → IF(0=0,1,MAX(IF(0,\$E\$4:\$E4,0)+IF(0>0,0,1)))
• Output: 1.
• We get this from the first part of the IF function as the condition is True, so we get the output as 1.

### 4. Using COUNTIFS Function to Create a Number Sequence Based on Criteria

In this last method, we will use the COUNTIFS function to create a number sequence based on conditions.

Steps:

• At first, select the cell range D5:D10 and type the following formula.

`=COUNTIFS(B\$5:B5,B5,C\$5:C5,C5)`

There are two conditions in this formula. The first one looks for the product type and the second one looks for the brand name. Now, whenever these two match, the formula increments the number and thus creates a number sequence based on criteria. • Lastly, press CTRL+ENTER. This will AutoFill the formula to the selected cells. ## Practice Section

We have added a practice dataset for each method in the Excel file. So that, you can follow along with our methods easily. ## Conclusion

We have shown you 4 handy approaches to how to create a number sequence in Excel based on criteria. If you face any problems regarding these methods or have any feedback for me, feel free to comment below. Moreover, you can visit our site ExcelDemy for more Excel-related articles. Thanks for reading, keep excelling!

## Related Articles #### Rafiul Haq

Hello! This is Rafiul. I am passionate about all things related to data and MS Excel is my favorite application. I want to make people's life easier by writing easy-to-follow and in-depth guides here at Exceldemy.

We will be happy to hear your thoughts 