# How to AutoFill Numbers in Excel with Filter (2 Methods)

We have the Names of some students along with their Department. In the Serial column, we are going to list the students serially with Filter activated.

### Method 1 – AutoFill Numbers in Excel with a Filter Using the SUBTOTAL Function

STEPS:

• Select the cell range B5:B14.
• Open the Home tab and go to Editing.
• From Find & Select, choose Go To Special.

• A dialog box will pop up.
• Select Visible cells only and click OK.

• Use this formula in the first selected cell or in the Formula bar.
`=SUBTOTAL(3,\$C\$5:C5)`

Formula Breakdown

\$C\$5:C5 >> This denotes an expanding range. The first element of the range is locked, so the first element will always remain the same. The second element will change if we drag down the formula.
Output is>> “Tom”
Explanation>> Here, it is the cell value of the C5 cell.
3,\$C\$5:C5 >> In this case, 3 denotes the COUNTA function. In the picture below we have given a list of numbers that denote different functions in the case of the SUBTOTAL function.

SUBTOTAL(3,\$C\$5:C5) >> Gives the total of cells with values in the selected range.
Output is >> 1 2 3 4 5 6 7 8 9 10
Explanation>> Returns a range of numbers for the selected cell range

• Press Ctrl + Enter as it’s an array formula.

• Filter the dataset with Physics and Finance in the Department. Click the filter icon.

• Select Physics and Finance.

• Excel will recalculate the Serials sequentially.

### Method 2 – Using the AGGREGATE function to AutoFill Numbers with a Filter

STEPS

• Apply Visible cell only to the range you are going to work with by following Method 1.
• Use the following formula in the Formula bar
`=AGGREGATE(3,7,\$D\$5:D5)`

Formula Breakdown

\$C\$5:C5 >> This denotes an expanding range. The first element of the range is locked, so the first element will always remain the same. The second element will change if we drag down the formula.
Output is >> “Tom”
Explanation >> Here, it is the cell value of C5 cell.

3,7,\$C\$5:C5 >> In this case, 3 denotes the COUNTA function. We have shown the list of functions that Excel shows in the image below.

In this case, 7 denotes the option Ignore hidden rows and error values. In the picture below, we have given a list of numbers that denote different options for the AGGREGATE function.

AGGREGATE(3,7,\$C\$5:C5) >> Returns the Serial numbers for the selected range.
Output is >> 1 2 3 4 5 6 7 8 9 10
Explanation >> Returns a range of numbers for the selected cell range.

• Press Ctrl + Enter as it’s an array formula.

• Filter from the Department column by selecting Physics and Finance like in Method 1.
• Excel will rearrange the Serial numbers.

Read More: How to Auto Number Cells in Excel

## Practice Workbook

We have attached a practice sheet for you to practice.

## Related Articles

<< Go Back to Autofill Numbers |

Get FREE Advanced Excel Exercises with Solutions!
Akib Bin Rashid

AKIB BIN RASHID, a materials and metallurgical engineer, is passionate about delving into Excel and VBA programming. To him, programming is a valuable time-saving tool for managing data, files, and internet-related tasks. Proficient in MS Office, AutoCAD, Excel, and VBA, he goes beyond the fundamentals. Holding a B.Sc in Materials and Metallurgical Engineering from Bangladesh University of Engineering and Technology, MD AKIB has transitioned into a content development role. Specializing in creating technical content centred around Excel and... Read Full Bio

1. I have a list of library books with various headings subheadings and comments interspersed with the data.
I can filter these out by selecting a column that only contains data if the line is an entry for a library book.
So I want to apply the filter (which I can do using your methods) but I want that number to be permanent regardless of what filter i apply.

2. Hi David
As far as I understand the case, you want to apply a filter to a row but keep the numbers in the cell permanent.
Unfortunately, when Excel executes a filter, it hides the entire row. If any cell contains numbers, excel will hide them too. However, as this article explains, you can maintain the serial when applying a filter.
In case I have misunderstood your requirement, please mail us the excel file at [email protected] and explain the problem a bit more.
Thank you.

Advanced Excel Exercises with Solutions PDF