Vba Code to generate highest number

singupalli

New Member
Joined
Apr 19, 2011
Messages
34
Hi

I need assistance.

need a code to generate auto numbers

In my data base sheet "Inventory" i have a column for Invoice numbers.

The code should verify this Column and generate the next highest number to the User form Invoice number text box.

can some one help please

Thank you
prasas
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I used a command button to trigger textbox to show the next available number. Not sure how your doing it.
Code:
Private Sub CommandButton1_Click()
Dim cMax As Variant
cMax = Application.WorksheetFunction.Max(Range("A:A"))
UserForm1.TextBox1.Value = cMax + 1
End Sub
You would need to change A:A to reflect the Inventory column. Also if your inventory column changes this code is not the best. You also need to update the Userform, Textbox, and command buttons names accordingly.
 
Last edited:
Upvote 0
I misread your post a bit, sorry for that. You would need to Range A:A to reflect the column which contains your invoice numbers.

Are you using any code currently?
 
Upvote 0
Place this code in the sheet it will be used:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cMax As Variant
cMax = Application.WorksheetFunction.Max(Range("A:A"))
Sheets("Inventory").TextBox1.Value = cMax + 1
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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