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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

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

change A1 to suit.
 

chuf

Well-known Member
Joined
Jun 12, 2006
Messages
619
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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
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
 

Forum statistics

Threads
1,136,272
Messages
5,674,748
Members
419,525
Latest member
helensesc

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
Top