Automatic Sequential Numbers

StephenM

New Member
Joined
Jun 15, 2004
Messages
2
I'm really new to the macros in excel, but I'm looking for something that will allow me to automatically generate a sequential number that can be used for an invoice or PO number. Once it uses the number it will go to the next number. I hope I'm clear in what I need, basically I have a PO form and everytime I open up a new form I want a new number in PO # box on the form. Could you also please either tell me or link me how to set-up the macro to get it working. Thanks!
 

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)
Welcome to the Board!

The following code will increment an existing number by 1 each time the workbook is opened. If you're starting blank, then it will automatically start at 1001. The code goes in the "ThisWorknbook" module.

<font face=Tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open()
    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range
        <SPAN style="color:#007F00">'   Set the range for PO # - Adjust Sheet & Range as necessary</SPAN>
        <SPAN style="color:#00007F">Set</SPAN> rng = Sheets("Sheet1").Range("A2")
    
    <SPAN style="color:#00007F">If</SPAN> rng = "" <SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#007F00">'   Set initial PO#</SPAN>
        rng = 1001
    <SPAN style="color:#007F00">'   Increment PO # by 1</SPAN>
    Else: rng.Value = rng.Value + 1
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Hope that helps,

Smitty
 
Upvote 0
To use the code whilst in xl hit Alt+F11. On the left hand side you should see the project explorer window (if not hit Ctrl+R). You should see your workbook listed as VBAProject (yourworkbook name) - double click on the ThisWorkbook module. Paste the code into this.

HTH
 
Upvote 0
Hit ALT+F11 to open the VB Editor. On the left hand pane, you'll see a folder called VBAProject(Filename.xls). Expand it and double-click on the module called "ThisWorkbook". Paste the code in the window that opens on the right. Then change this: Sheets("Sheet1").Range("A2") to reflect the specific sheet name and range where you want the PO number stored.

You can hit F5 to test the code.

ALT+Q to exit VBA and return to your workbook.

The next time you open the workbook, the PO # will increment by 1.

Hope that helps,

Smitty

EDIT: Iridium beat me to it :wink: (What's up Bud?)
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

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