Skip to main content

How to fill down sequence numbers skip hidden rows in Excel?

Author: Xiaoyang Last Modified: 2024-10-10

Supposing, you have a filter data range which you want to fill down sequence numbers into the filtered blank cell as following screenshot shown. In this case, dragging the fill handle will not fill the cells correctly generally, this article, I will talk about some good tricks for solving this task in Excel.

A screenshot showing a dataset where sequence numbers will be filled into visible rows Arrow A screenshot showing sequence numbers filled into visible rows and skipped hidden rows

Fill down sequence numbers skip hidden rows with formula

Fill down sequence numbers skip hidden rows with VBA code

Fill down sequence numbers skip hidden rows with Kutools for Excel


Fill down sequence numbers skip hidden rows with formula

To fill down sequence numbers only to the visible cells, a simple formula may help you, please do as follows:

1. Enter this formula: =SUBTOTAL(103,$B$3:$B3)(B3 is the visible cell which corresponding to the cell that you want to start filling the sequence number to ) into the first cell where you want to fill sequence numbers, A3, for this instance, and then press Enter key, you will get a number 1, see screenshot:

A screenshot showing the first sequence number in a visible row using a formula

2. Then select cell A3, and drag the fill handle down to the cells that you want to fill the sequence numbers, see screenshot:

A screenshot showing sequence numbers filled into visible rows in Excel using a formula


Fill down sequence numbers skip hidden rows with VBA code

The following VBA code also can help you to fill the sequence numbers into only visible cells, please do as this:

1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Fill down sequence numbers skip hidden rows:

Sub FillValue()
'updateby Extendoffice
    Dim xRg As Range
    Dim xCell As Range
    Dim xTxt As String
    Dim xVal As Long
    Dim I As Long
    On Error Resume Next
    xTxt = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Please select the data range", "Kutools for Excel", xTxt, , , , , 8)
    Set xRg = xRg.SpecialCells(xlVisible)
    Debug.Print xRg.Address
    If xRg Is Nothing Then Exit Sub
    For Each xCell In xRg
        xVal = xVal + 1
        xCell = xVal
    Next
End Sub

3. Then press F5 key to run this code, and a prompt box is popped out to remind you select the data range that you want to fill, see screenshot:

A screenshot showing a VBA input box for selecting data to fill sequence numbers

4. And then click OK button, the sequence numbers have been filled into the visible cells only.


Fill down sequence numbers skip hidden rows with Kutools for Excel

Above two methods only can help you to fill down the sequence numbers into the visible cells, if you want to fill sequence as AA-0001-BB, AA-0002-BB,AA-0003-BB…, the above methods will not work. But, please don’t worry about, Kutools for Excel’s Insert Sequence Number utility can help you finish it quickly and easily.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

After installing Kutools for Excel, please do as follows:

1. Select the cells that you want to fill sequence strings.

2. Click Kutools > Insert > Insert Sequence Number, in the Insert Sequence Number dialog box, click New button, see screenshots:

A screenshot showing the Insert Sequence Number option on the Kutools tab on the ribbon Arrow A screenshot showing the Insert Sequence Number dialog

3. In the expanded dialog box, please specify the settings as your needed into the left bottom section, at the same time, you can preview the sequence in the right bottom pane, see screenshot:

A screenshot showing sequence number settings

4. After finishing the settings, click Add button to save this new item into the above list box, see screenshot:

A screenshot showing custom sequence number preview

6. And then select the item you are created and click Fill Range button, the sequence strings have been filled into only the visible cells, see screenshot:

A screenshot showing sequence numbers filled into visible cells in Excel using Kutools

Download and free trial Kutools for Excel Now !


Demo: Fill down sequence numbers skip hidden rows with Kutools for Excel

Kutools for Excel: Over 300 handy tools at your fingertips! Enjoy permanently free AI features! Download Now!

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!