How to Update Sequence Number for Rows Automatically After Inserting or Deleting Rows in Excel

Sometimes we add sequence number in the first column for each row in a table, for example create a table for saving student info, and one student one row. If I insert a new student info or delete an existing student info, the sequence numbers for rows are cut off and not continuous anymore. If we want to make these numbers are still continuous automatically after inserting or deleting rows, do you have any tricks? Actually, there are some methods you can follow to update sequence number for rows automatically, this article will introduce you two methods to implement this.

Precondition:

See table below. In first column, there are sequence numbers for rows.

Update Sequence Number for Rows Automatically 1

If we insert a new row or delete an existing row from the table, obviously numbers are not continuous. So, we need to know the method to update sequence number automatically.

Method 1: Update Sequence Number for Rows Automatically by Formula


Step 1: You can see that except the header, sequence number for each row equals to row number minus 1. So, we can use =ROW()-1 to get sequence number here. In B2 enter the formula =ROW()-1. Then drag it down to fill other cells till A13.

Update Sequence Number for Rows Automatically 2

Please notice that if there is no header in table and sequence number is started in A1, you can just enter =ROW() here.

Step 2: Create table for this table. Select this table, click Insert tab in ribbon, click Table.

Update Sequence Number for Rows Automatically 3

Verify that Create Table dialog pops up. As table range is already selected, so $A$1:$C$13 is auto selected, and option ‘My table has headers’ is checked by default. Click OK.

Update Sequence Number for Rows Automatically 4

Verify that table is created and table style is updated. Now, after creating table, sequence number will be automatically updated.

Update Sequence Number for Rows Automatically 5

Step 3: Try to insert a new row between number 6 and 7.

Update Sequence Number for Rows Automatically 6

Verify that sequence number is updated automatically.

Step 4: Try to delete an existing record.

Update Sequence Number for Rows Automatically 7

Verify that sequence number is updated automatically.

Method 2: Update Sequence Number for Rows Automatically by VBA Code


Notice: If you want to only delete row from table and then automatically update sequence number, you can also edit VBA code to implement this.

Step 1: On current visible worksheet, right click on sheet name tab to load Sheet management menu. Select View Code, Microsoft Visual Basic for Applications window pops up.

Or you can enter Microsoft Visual Basic for Applications window via Developer->Visual Basic. You can also press Alt + F11 keys simultaneously to open it.

Step 2: In Microsoft Visual Basic for Applications window, enter below code:

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim i As Integer

    i = 2

    Application.EnableEvents = False

    For i = 2 To 13

        Range("A" & i).Value = i - 1

    Next

    Range("A13").Value = ""

    Application.EnableEvents = True

End Sub

Comments:

  1. Sequence number is started in A2, so we can define i=2, and For i = 2 To 13 (13 is the last row number in table), Range(“A” & i).Value = i – 1.
  2. In Range(“A13”).Value = “”, A13 is the last cell in sequence number. You can change it.

Step 3: Try to delete an existing record.

Update Sequence Number for Rows Automatically 8

Verify that sequence numbers are still continuous after updating.

 

 

Related Posts

Calculate Years Between Dates In Ms Excel

If you are an avid Ms Excel user, then you might have come across a task in which you needed to calculate the years between the dates; you might take it easy and do this task manually, which is also ...

Calculate Number of Hours between Two Times

Calculating the difference between two times might be a valuable statistic for subsequent computations or averages, whether you're producing a time sheet for staff or recording personal exercises. While Excel has a plethora of complex functions, including date and time ...

Calculate Loan Interest in Given Year

When you borrow money, you are supposed to repay it gradually. Lenders, on the other hand, want to be compensated for their services and the risk they incur by lending you money. That is, you will not just repay the ...

Calculate Interest Rate for Loan

The interest rate is the fee charged by a lender to a borrower and is expressed as a percentage of the principal—the lent amount. The interest rate on a loan is often expressed as an annual percentage rate, abbreviated as ...

Calculate Interest for Given Period

Using the IPMT function in Excel, we can compute the interest payment on any loan. This step-by-step tutorial will guide Excel users of all skill levels through the process to calculate interest for given period. Finally, the formula: =IPMT(B3/12,1,B5,-B2) The ...

How To Use Excel GCD Function

This post will guide you how to use Excel GCD function with syntax and examples in Microsoft excel. Description The Excel GCD function Returns the greatest common divisor of two or more integers. So you can use the GCD function ...

Calculate A Ratio From Two Numbers In Excel

In elementary mathematics, a ratio is a connection or comparison between two or more integers. For example, ratios are often expressed as ":" to demonstrate the relationship between two numbers. You would think that manually calculating a ratio from two ...

How To Use Excel RRI Function

This post will guide you how to use Excel RRI function with syntax and examples in Microsoft excel. Description The Excel RRI function Returns an equivalent interest rate for the growth of an investment. So you can use the RRI ...

CAGR Formula Examples in Excel

CAGR in Excel is a formula that calculates the compound annual growth rate for any invested amount over the specified years or timeframe. Although there is no direct function in Excel that can help us identify the CAGR value, there ...

Build Hyperlink With VLOOKUP in Excel

You might have come across a task in which you were assigned to build hyperlinks, which seems very easy, and if you are new to excel or don't have enough experience with it, then you might wonder about doing this ...

Sidebar