VBA to Make Advancing ID numbers

Chelsea0270516

New Member
Joined
Oct 15, 2015
Messages
32
Basically I review & reconcile a large invoice & invoice log for work. I'd like to make something that will automatically put the next highest number (base on what was previously entered during the current session) into the Invoice column. A couple things:


  • It can't use the existing numbers in the Invoice column as a reference - some of them are very large/out of the norm & I can't change old entries.
  • I'd be okay with manually updating the starting Invoice number each time I use the code OR making some file I have open that it references if that would be easier.
  • Needs to be in my personal workbook as the log can't be saved with macros.
  • Column C is hidden in the active sheet I work in.

If anyone can point me in the right direction I am happy to research & test code, I just don't know what code I should be using so searching has been hard.

My thought was to define a variable as an integer, manually set it equal to something, set it to drop into the invoice column of the active sheet, then redefine the variable as the previous one +1. BUT I am having a horrible time figuring out how to make that last part happen.

Obviously the code below isn't working. I used Integer as my variable, but if there is something better...that is cool too!

Looking at it I can see that every time I run it the starting INV will be 3322610300, I just don't know the right logic to make that happen.

Sub NextInv()
'inserts Inv Sum
'I want to make something that will remember what I previously used - redefine the variable?


Dim Inv As Integer

Inv = 3322610300

ActiveCell.Offset(1, 0).Range("A1:H1").Select
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = Inv

Inv = Inv + 1

End Sub




POStore#Order #Order DateDollar AmountPacking SlipCode asInvoice #Summary Inv#
J0523-2308230871184540205/23/2012$28.11Yes7-72080-8650032328898058030076355
J0523-2308230871184540205/23/2012$87.18Yes7-72080-8650032361190088030491954

<colgroup><col><col><col><col><col><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi,

It sounds like you need to find the largest invoice number after a certain date. Would that work?

If so, then you could increment that.

Another approach would be to use another Worksheet that has the next number to use stored in it. You could hide that sheet if being visible was a problem.


Regards,
 
Upvote 0
Hi Rick! The second approach is something I could do! I played with it a little & have the code below which works! I added in another invoice number (that doesn't change) so it is inputing two invoices now.

If anyone comes up with a cleaner way to do it (Or could explain a better way to write what I have below) I'd love to hear it.

Sub NextInvANDInvSum()

'inserts Inv Sum
'I want to make something that will remember what I previously used - redefine the variable


Dim Inv As Double
Dim SumInv As Double

Inv = ActiveWorkbook.Sheets("Sheet1").Range("A1")
SumInv = ActiveWorkbook.Sheets("Sheet1").Range("A2")

ActiveCell.Offset(1, 0).Range("A1:H1").Select
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = Inv
ActiveCell.Offset(1, 0).Range("A1:I1").Select
ActiveCell.Offset(-1, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = SumInv

ActiveWorkbook.Sheets("Sheet1").Range("A1") = Inv + 1



End Sub
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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