This is code for a user form with a text box, a listbox and 4 command buttons, butAdd, butClose, butDelete and butGo.
Your post sounds like your worksheets are alphabetized and that you have a template for the added sheets.
This code assumes that that template sheet is named "Template"
It also assumes that there is a Master sheet that you want to be to the left of all sheets and is separate from the alphabetization.
If there is more than one unsorted sheet at the left of the tabs, change the FirstFreeSheet variable in SortAllWorksheets as needed. (If all the sheets are in the sort, FirstFreeSheet should equal 1). You might want to include the template sheet in the unmoving sheets.
Code:
Dim HomeSheet As Worksheet
Private Sub butAdd_Click()
If TextBox1.Text <> vbNullString Then
With ThisWorkbook
If MsgBox("Add a new sheet named " & TextBox1.Text & vbCr & "There is no undo.", vbYesNo + vbDefaultButton2) = vbYes Then
.Sheets("Template").Copy after:=.Sheets(.Sheets.Count)
ActiveSheet.Name = TextBox1.Text
Set HomeSheet = ActiveSheet
Call AlphabetizeAllWorksheets
End If
End With
End If
End Sub
Private Sub butClose_Click()
HomeSheet.Activate
Unload Me
End Sub
Private Sub butDelete_Click()
With ListBox1
If .ListIndex <> -1 Then
If MsgBox("Delete sheet " & .Text & vbCr & "There is no undo.", vbYesNo + vbDefaultButton2) = vbYes Then
Application.DisplayAlerts = False
ThisWorkbook.Sheets(.Text).Delete
Application.DisplayAlerts = True
UserForm_Initialize
End If
End If
End With
End Sub
Private Sub butGo_Click()
Unload Me
End Sub
Sub AlphabetizeAllWorksheets()
Dim FirstSheet As Worksheet
Dim FirstFreeSheet As Long
Dim i As Long
Dim j As Long
FirstFreeSheet = 2
With ThisWorkbook
For i = .Sheets.Count To FirstFreeSheet Step -1
For j = FirstFreeSheet To .Sheets.Count
If LCase(.Sheets(i).Name) < LCase(.Sheets(j).Name) Then
.Sheets(i).Move before:=.Sheets(j)
Exit For
End If
Next j
Next i
End With
End Sub
Private Sub ListBox1_Click()
ThisWorkbook.Sheets(ListBox1.Text).Activate
butDelete.Enabled = True
butGo.Enabled = True
End Sub
Private Sub TextBox1_Change()
Dim i As Long
With ListBox1
.ListIndex = -1
butDelete.Enabled = False
butGo.Enabled = False
If TextBox1.Text <> vbNullString Then
For i = 0 To .ListCount - 1
If LCase(.List(i)) Like LCase(TextBox1.Text & "*") Then
.ListIndex = i
butDelete.Enabled = True
butGo.Enabled = True
Exit Sub
End If
Next i
End If
End With
butAdd.Enabled = Not (butDelete.Enabled) And (TextBox1.Text <> vbNullString)
End Sub
Private Sub UserForm_Initialize()
Dim i As Long, j As Long, oneSheet As Worksheet
With ListBox1
.Clear
For Each oneSheet In ThisWorkbook.Sheets
If 0 < .ListCount Then
For j = 0 To .ListCount - 1
If oneSheet.Name < .List(j) Then
Exit For
End If
Next j
End If
.AddItem oneSheet.Name, j
Next oneSheet
End With
butGo.Enabled = False
butAdd.Enabled = False
butDelete.Enabled = False
Set HomeSheet = ActiveSheet
End Sub
Note: there is no error checking for illegal sheet names of added sheets.