Creating auto generated numbers in excel database

anshikam

Board Regular
Joined
Aug 20, 2016
Messages
87
Hello,

I have an excel database where I have 1 column for a UID no which is pretty much a serial number.
I need a formula where the number would auto generate based on the number in the last row +1.
Currently have the formula set where the value of the first row is set at 1 and second row is a1+1 and so on.
However, when I delete a record or add to the database this goes haywire and i have to fix the formulas.

Any work around this?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You cannot do it by formula and expect it to remain static thereafter

VBA required
eg this adds 1 to the value of the last used row in column A and places the value in the empty cell in the next row
VBA Code:
Sub AddOne()
    With ActiveSheet.Cells(Rows.Count, "A").End(xlUp)
        .Offset(1) = .Value + 1
    End With
End Sub
 
Upvote 0
I
You cannot do it by formula and expect it to remain static thereafter

VBA required
eg this adds 1 to the value of the last used row in column A and places the value in the empty cell in the next row
VBA Code:
Sub AddOne()
    With ActiveSheet.Cells(Rows.Count, "A").End(xlUp)
        .Offset(1) = .Value + 1
    End With
End Sub
am constantly deleting records mid database. Therefore cant use previous row cause it may not always be accurate.
 
Upvote 0
I am puzzled :unsure:

I need a formula where the number would auto generate based on the number in the last row +1.

Please EXPLAIN why adding 1 to the value of the last used cell in column does not work when that is exactly what you requested
 
Upvote 0
I am puzzled :unsure:



Please EXPLAIN why adding 1 to the value of the last used cell in column does not work when that is exactly what you requested
It does work. However I have to constantly redrag the formulas to copy in all cells. Everytime i delete a row or add a row it errors and the last serial no is incorrect. The database is in a table. So when i delete a row its not recognizing that for instance then i have 2 rows with sr no as 9 where as it should be 9 and 10 when a row is added. I run several VBA Scripts on this database and have to assign the value of the particular cell which i do. But its pointless since i have to keep redoing the formula.
 
Upvote 0
Ah - now I understand your problem

I mentioned above that you CANNOT use a formula - all numbers in that column must be made static

1. Select the column, COPY & PasteSpecial VALUES

Paste Special.jpg


2. Use VBA (provided above) for future values

You must NOT delete the last row otherwise your numbering will go wrong
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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