Auto number

niecie

New Member
Joined
Jan 20, 2005
Messages
5
I am creating a transmittal form for a client. One of the features they would like in the form is to have the form change in increments of 1 everytime the form is opened. For example, the form is like an invoice. So they want the cell in which the "invoice number" resides to change everytime the form is opened. Can you help?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,021
Office Version
  1. 365
How about storing the value in some hidden, unused cell?

Then, code similar to this msgbox example might work:

Sub box()
Sheets("sheet1").Range("z1") = Sheets("sheet1").Range("z1").Value + 1
MsgBox "This is number "&Sheets("sheet1").Range("z1").Value , vbOKOnly, "Invoice #" & Sheets("sheet1").Range("z1")
End Sub
 

JPM

Active Member
Joined
Aug 1, 2002
Messages
406
What you can do is to add the following code to the sheet (not a module)
Code:
Private Sub Worksheet_Activate()
Invoice = Range("I3").Value + 1 'if the invoice number is in cell I3
Range("I3").Formula = Invoice
End Sub
The only problem with this is that it will update the number everytime it is activated. So if you want to look at the same invoice again in a few days, it will update itself again.

JPM
 

JPM

Active Member
Joined
Aug 1, 2002
Messages
406
You could however disable the macro when you reopen the file, which then would not change the number.

JPM
 

Forum statistics

Threads
1,147,846
Messages
5,743,521
Members
423,801
Latest member
paulj4177

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