add 1 to an invoice no. everytime its opened

chuf

Well-known Member
Joined
Jun 12, 2006
Messages
619
I've read the answer to this on here before but i can't find it.
Sorry.

If I want to open a template for an invoice.. and each time its opened i want it to add 1 to the invoice number to make an automatically sequential system. could someone tell me how to do it please ?
i think it was a vba code.

also would the spreadsheet need to be saved each time, say it was a template and you wanted to use different details everytime therefore you'd be resaving it as something else anyway, how would this work ?

thanks guys.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try

Code:
Sub Auto_Open()
Range("A1").Value = Range("A1").Value + 1
End Sub

change A1 to suit.
 
Upvote 0
oops, :confused:

i'm a newbie so i must be doing something wrong.

just tried this..

i opened up new spreadsheet posted this code into the view code function on tab then imput number into a1.

closed , reopened and it didn't move on.

what am i doing wrong please ? do i need to specify the spreadsheet name in the code somewhere.

thanks
 
Upvote 0
ALT + F11 to open the Visual Basic Editor. Insert > Module, copy the code and paste it in. Close the VBE. Now each time you open the workbook A1 should increment by 1. You have to remember to save it of course. You may want to amend the code to look at a specific sheet:

Code:
Sheets("Sheet1").Range("A1").Value = Sheets("Sheet1").Range("A1").Value + 1
 
Upvote 0
Just a note that Workbook_Open is preferred over Auto_Open in versions '97 and up.

In which case it's:

Code:
Private Sub Workbook_Open()
  '  Code here
End Sub

The code goes in the ThisWorkbook module.

HTH,

Smitty
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

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