Auto number when a row is inserted

FireBott

Board Regular
Joined
Nov 10, 2003
Messages
72
Office Version
  1. 2016
Platform
  1. Windows
Good Afternoon. I have a spreadsheet to collect the necessary activities to onboard a new client. There will be approximately 7 people making contributions to the spreadsheet on a shared drive. The end result will eventually become a project plan/timeline. The spreadsheet is in a table format with 801 rows (Table 4 = B1:J801), the first row being the header. The rows are automatically numbered using =row(B1); column name Activity ID. However, there will be times that a user will need to insert a row which will mess up the Activity ID sequence. Is there a formula or code that when a row is inserted, the Activity ID number will populate sequentially using the last number populated at the end of the table?

For example, The last row in the table is numbered 800, if a user inserts a row in between Activity ID 10 and 11, have the formula/code automatically number the new row 801.

1717011879792.png


Thank you in advance.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In the module of this sheet (e.g. Sheet1), and NOT in the standard module (e.g. Module1), paste the following event procedure:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Target.ListObject.ListColumns(1).DataBodyRange) Is Nothing Then
        Application.EnableEvents = False
        With Target.ListObject.ListColumns(1).DataBodyRange
            .Cells(1).Value = 1
            .DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                Step:=1, Stop:=.Cells.Count, Trend:=False
        End With
        Application.EnableEvents = True
    End If
End Sub
Artik
 
Upvote 0
As a formula you could try something like this:
Excel Formula:
=ROW()-ROW(Table4[[#Headers],[Activity ID]])
 
Upvote 0
Another option as long as the Activity column is unique.
Book1
ABC
1IDActivity
21A
32B
43C
54D
65J
76H
87E
98F
Sheet8
Cell Formulas
RangeFormula
B2:B9B2=MATCH([@Activity],[Activity],0)
 
Upvote 0
In the module of this sheet (e.g. Sheet1), and NOT in the standard module (e.g. Module1), paste the following event procedure:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Target.ListObject.ListColumns(1).DataBodyRange) Is Nothing Then
        Application.EnableEvents = False
        With Target.ListObject.ListColumns(1).DataBodyRange
            .Cells(1).Value = 1
            .DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
                Step:=1, Stop:=.Cells.Count, Trend:=False
        End With
        Application.EnableEvents = True
    End If
End Sub
Artik
 
Upvote 0
Hi Artik,
Thank you for this code. However, when I copy it I get an error. Any ideas?
1717108006057.png
 
Upvote 0
It seems that problems arose when copying the code. Remove the empty line between .DataSeries (...) and Step:=1, (...).
Also remove the [/code] tag in the End Sub line.

Artik
 
Upvote 0
Solution
It seems that problems arose when copying the code. Remove the empty line between .DataSeries (...) and Step:=1, (...).
Also remove the [/code] tag in the End Sub line.

Artik
Thank you. That was the solution. Have a great week.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,115
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top