Generate next requisition number in sequence

tahjb

New Member
Joined
Oct 9, 2019
Messages
10
[COLOR=rgba(0, 0, 0, 0.9)]Hey Excel Guru's -Looking for a little help with VBA code. I'm generating a requisition number on a form and each time I save the file I need excel to generate the next number in line. The below code partially works, but when I get to a certain number it keeps increasing the number of digits...Range("H4").Value = Left(Range("H4").Value, 4) & Mid(Range("H4").Value, 4, 4) + 1For example, I would want the requisition number to go in sequence: 05-1000, 05-1001, 05-1002 and so on. But, issue occurs and it jumps from 05-1000 to 05-11001 and adds a digitAny tips or pointers.Thank You[/COLOR]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Welcome to the forum. This code will increment the requisition number in range H4 each time the workbook is saved.

Make sure to paste the code below in the workbook after save event.

Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim SP() As String: SP = Split(Range("H4").Value, "-")
If SP(1) = 9999 Then
    SP(0) = SP(0) + 1
    SP(1) = 1000
Else
    SP(1) = SP(1) + 1
End If


Range("H4").Value = Join(SP, "-")
End Sub
 
Upvote 0
Welcome to the forum. This code will increment the requisition number in range H4 each time the workbook is saved.

Make sure to paste the code below in the workbook after save event.

Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim SP() As String: SP = Split(Range("H4").Value, "-")
If SP(1) = 9999 Then
    SP(0) = SP(0) + 1
    SP(1) = 1000
Else
    SP(1) = SP(1) + 1
End If


Range("H4").Value = Join(SP, "-")
End Sub


Thanks will give a try!
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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