auto generate sequential numbers

MCE2014

New Member
Joined
Sep 15, 2014
Messages
21
Im trying to create a job number generater.

I have the following code:

Dim NextNum As Long

NextNum = Application.WorksheetFunction.Max(Sheet1.UsedRange.Columns(1))

Me.txtjobno.Value = NextNum
Me.txtjobno.Enabled = False

Anybody know how I can get the program to remember the last number issued and continue on from the next sequential number even after being closed and reopened???

Also I want it to start at 1 and not at 0
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi, presumably you will be writing the numbers to column 1?

If so, won't the previous highest number be saved there? You just need to find it using the MAX statement again.

As for starting at 1 there are several choices:
You could enter the first one manually or you could add an IF statement to your logic which says if the number is 0 (or blank) then add 1 to it.
 
Upvote 0
NextNum should be incremented by 1 over the maximum found so this would even work if there was no data. Change to:

Code:
NextNum = Application.WorksheetFunction.Max(Sheet1.UsedRange.Columns(1)) + 1

A note to remember is that Columns(1) is referenced to the UsedRange, not the sheet. If you happened to have Column A empty with data starting in Column B then that would return the Column B maximum.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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