Skip Hidden Rows in Sequential Numbering in Google Sheets

In Google Sheets, we use Data > Create a Filter or manually hide rows to focus on specific parts of a table or to print only relevant sections. When you have a serial number column, hidden rows can cause the numbering to lose continuity. So, how do you resolve this? Specifically, how do you skip hidden rows in sequential numbering to get the correct numbering in the visible rows? You can use the following formula for this:

=SUBTOTAL(103, $A$1:A1)

Sequential Numbering in Visible Rows – Example

Assume you have text in column C in the range C2:C. You can use the following formula in cell B2 and drag it down to get sequential numbers in visible rows:

=SUBTOTAL(103, $C$2:C2)
Example of Skipping Hidden Rows in Sequential Numbering in Google Sheets

The SUBTOTAL function with the number 103 represents the COUNTA function. It returns the count of values in visible rows up to the current row. When you drag the formula down, it will assign sequential numbers in visible rows.

The numbers in hidden rows will be the same as the number of the visible row above them. Since the hidden rows are not visible, this won’t cause any issues.

If all the rows are visible, you will get regular serial numbers. This ensures that you always have continuous numbering, regardless of whether rows are hidden or not.

Fill Sequential Numbers While Skipping Hidden Rows: Key Considerations

Important:

When using this formula, make sure that the column for which you are numbering the rows is not empty. For instance, in the above example, the formula expects values in all cells in the range C2:C13. If you expect empty cells, you should consider using a helper column.

Addressing Empty Rows Using a Helper Column

For example, you can enter the following formula in cell D2:

=ArrayFormula(SEQUENCE(XMATCH(TRUE, C2:C<>"", 0, -1)))

Then, hide column D. Afterward, use the following formula in cell B2 and drag it down:

=SUBTOTAL(103, $D$2:D2)

This will allow you to skip hidden rows and include empty rows while maintaining sequential numbering.

Skip Hidden Rows Dynamically in Sequential Numbering in Google Sheets

In our example, we used a drag-down formula. However, it may break if you insert rows between existing data. The best way to handle numbering rows while skipping hidden rows is to use an ArrayFormula.

The SUBTOTAL function won’t expand when used with ARRAYFORMULA, so we can use the MAP lambda helper function to achieve this:

=ARRAYFORMULA(IF(C2:C="",,MAP(C2:C, LAMBDA(Σ, SUBTOTAL(103, C2:Σ)))))

Insert this formula in cell B2 after clearing the range B2:B to allow it to expand.

We transformed =SUBTOTAL(103, $C$2:C2) into an unnamed custom lambda function as follows:

LAMBDA(Σ, SUBTOTAL(103, C2:Σ))

Then, we applied this to each element in the array C2:C using the MAP lambda helper function.

In the above formula, Σ represents the current element in the array.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Cycle Highlights in Google Sheets – Rotate Highlights Daily

Want to cycle highlights in Google Sheets every day? Whether you're rotating a meal...

Filter Rows Containing Multiple Selected Values in Google Sheets

This tutorial explains how to filter rows in a column containing multiple selected drop-down...

Two-Way Lookup with XLOOKUP in Google Sheets

When you need to look up one search key vertically and another horizontally, you...

How to Filter by Total in Google Sheets Pivot Tables

Google Sheets offers many tools to summarize and analyze data, but Pivot Tables are...

More like this

Cycle Highlights in Google Sheets – Rotate Highlights Daily

Want to cycle highlights in Google Sheets every day? Whether you're rotating a meal...

Filter Rows Containing Multiple Selected Values in Google Sheets

This tutorial explains how to filter rows in a column containing multiple selected drop-down...

Two-Way Lookup with XLOOKUP in Google Sheets

When you need to look up one search key vertically and another horizontally, you...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.