S
S Davis
Hello all,
I have a Macros that creates a copy of a Template worksheet, prompts
the user for a Workorder number, then inserts a sheet with the name as
the Workorder number (ie. 123456).
What I would like to be able to do is insert this sheet into its
correct position. ie. if a user has already inserted two worksheets
named 1234567 and 8901234, if they then try and insert a new worksheet
titled 4567890, I would like it to insert itself in between the other
two workorder numbers. This will make it easier to find.
Currently is is simply inserted after a sheet titled "Materials." I'd
like to still have the sheet inserted after the Materials sheet, but
be inserted in its proper numerical position after that sheet.
Here is my code currently. Thank you for any help!
Sub InsertSheetWUniqueName()
WorkorderNumber = InputBox("This will create an auto-generating
Workorder Tracking Sheet for all children of a Parent Workorder.
Please enter Parent Workorder Number", "CREATE WORKORDER TRACKING
SHEET")
If WorkorderNumber = "" Then
MsgBox "Nothing Entered", vbOKOnly, "Cancelling..."
Else
On Error Resume Next
Sheets("Template").Copy After:=Sheets("Materials")
ActiveSheet.Name = WorkorderNumber
Range("B2").Select
ActiveCell.FormulaR1C1 = WorkorderNumber
Range("E2").Select
If Err.Number > 0 Then
MsgBox "Please Enter a Different Workorder Number", vbOKOnly,
"Sheet Already Exists"
Err.Clear
Application.DisplayAlerts = False
ActiveSheet.Delete
Sheets("Admin").Select
Application.DisplayAlerts = True
End If
On Error GoTo 0
End If
End Sub
I have a Macros that creates a copy of a Template worksheet, prompts
the user for a Workorder number, then inserts a sheet with the name as
the Workorder number (ie. 123456).
What I would like to be able to do is insert this sheet into its
correct position. ie. if a user has already inserted two worksheets
named 1234567 and 8901234, if they then try and insert a new worksheet
titled 4567890, I would like it to insert itself in between the other
two workorder numbers. This will make it easier to find.
Currently is is simply inserted after a sheet titled "Materials." I'd
like to still have the sheet inserted after the Materials sheet, but
be inserted in its proper numerical position after that sheet.
Here is my code currently. Thank you for any help!
Sub InsertSheetWUniqueName()
WorkorderNumber = InputBox("This will create an auto-generating
Workorder Tracking Sheet for all children of a Parent Workorder.
Please enter Parent Workorder Number", "CREATE WORKORDER TRACKING
SHEET")
If WorkorderNumber = "" Then
MsgBox "Nothing Entered", vbOKOnly, "Cancelling..."
Else
On Error Resume Next
Sheets("Template").Copy After:=Sheets("Materials")
ActiveSheet.Name = WorkorderNumber
Range("B2").Select
ActiveCell.FormulaR1C1 = WorkorderNumber
Range("E2").Select
If Err.Number > 0 Then
MsgBox "Please Enter a Different Workorder Number", vbOKOnly,
"Sheet Already Exists"
Err.Clear
Application.DisplayAlerts = False
ActiveSheet.Delete
Sheets("Admin").Select
Application.DisplayAlerts = True
End If
On Error GoTo 0
End If
End Sub