# Generate next requisition number in sequence

#### tahjb

##### New Member
[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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

#### lrobbo314

##### Well-known Member
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``````

#### tahjb

##### New Member
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!

Replies
22
Views
245
Replies
4
Views
70
Replies
6
Views
3K
Replies
4
Views
149
Replies
12
Views
134

1,109,398
Messages
5,528,503
Members
409,820
Latest member
gabrielrms

### This Week's Hot Topics

• Change military grades into rank
Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
• VBA COUNTIF SOLUTION
Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
• INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...