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]
 

Some videos you may like

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
Joined
Jul 14, 2008
Messages
2,848
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
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
Joined
Oct 9, 2019
Messages
10
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!
 

Watch MrExcel Video

Forum statistics

Threads
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...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top