[EXCEL] Automatic Numbering VBA
spaceshipone
Posted messages
8
Status
Member
-
michel_m Posted messages 18903 Registration date Status Contributor Last intervention -
michel_m Posted messages 18903 Registration date Status Contributor Last intervention -
Hello, here is my problem:
I created a form in VBA under Excel with a number for each record that needs to be managed automatically.
It needs to go through the existing list and retrieve the last number. And it should increment the number for each new record.
Can someone help me?
I created a form in VBA under Excel with a number for each record that needs to be managed automatically.
It needs to go through the existing list and retrieve the last number. And it should increment the number for each new record.
Can someone help me?
Configuration: Windows XP Internet Explorer 7.0
2 answers
Good evening,
First of all, you need to create a new function to increment a number by 1:
Then, if for example the numbers are located in column A in cells A2, A3, A4....An
A macro that will look for this last created number in An, increment it by 1 and write this new number in A(n+1):
There you go, I hope this helps you or gives you a lead
Good night
--
"To find a solution to your problems, you have to make an effort."
First of all, you need to create a new function to increment a number by 1:
Function NewNumber(LastNum) NewNumber = LastNum + 1 End Function
Then, if for example the numbers are located in column A in cells A2, A3, A4....An
A macro that will look for this last created number in An, increment it by 1 and write this new number in A(n+1):
Sub AssignNewNum() Dim LastNum As Integer 'LastNum is the last created number LastNum = Range("A2").End(xlDown).Value NewNum = NewNumber(LastNum) LastCell = Range("A2").End(xlDown).Address 'LastCell is the last cell containing the last number Range(LastCell).Activate ActiveCell.Offset(1, 0).Value = NewNum 'writes the new number in the empty cell below End Sub There you go, I hope this helps you or gives you a lead
Good night
--
"To find a solution to your problems, you have to make an effort."