I have a Range named “Database” which starts as $A$9:$M$10. I’ve attached the following code to a button on the sheet, which appends a new line to the bottom of the range and numbers it sequentially.
This works fine when starting from scratch, ie with no data in Database, clicking the button will number cell A10 as “1”, A11 as “2”, A12 as “3”and so on. The problem arises if I delete a row, then add a new one, I end up with duplicate row numbers ![[sad] [sad] [sad]](/data/assets/smilies/sad.gif)
For example, if I’ve got rows numbered 1 to 5, then delete row 3, the next new row is numbered 5. Any ideas how to avoid this duplication would be gratefully received![[wink] [wink] [wink]](/data/assets/smilies/wink.gif)
Chris
Varium et mutabile semper Excel
Code:
Public Sub BottomLine()
Application.ScreenUpdating = False
Dim iRowCount As Integer
With Range("Database")
' Count the number of existing rows, resize the database range,
' then assign values to the RefNo Cell.
iRowCount = .Rows.Count + 1
.Resize(iRowCount).Name = "Database"
RefNo = iRowCount - 1
End With
' Number the new row as RefNo.
Range("A65536").End(xlUp).Offset(1, 0).Value = RefNo – 1
End Sub
![[sad] [sad] [sad]](/data/assets/smilies/sad.gif)
For example, if I’ve got rows numbered 1 to 5, then delete row 3, the next new row is numbered 5. Any ideas how to avoid this duplication would be gratefully received
![[wink] [wink] [wink]](/data/assets/smilies/wink.gif)
Chris
Varium et mutabile semper Excel