Workbook Management Intermediate

Sheet Operations Manager

Add, rename, delete, and organise worksheets with advanced options

42 views
Featured

Perfect For:

  • Workbook setup
  • Sheet organisation
  • Template creation
VBA Code
Sub ManageWorksheets()
    Dim operation As String
    Dim sheetName As String
    Dim newName As String
    Dim ws As Worksheet

    operation = InputBox("Choose operation: ADD, RENAME, DELETE, or ORGANIZE:", "Sheet Manager")

    Select Case UCase(operation)
        Case "ADD"
            sheetName = InputBox("Enter name for new sheet:")
            If sheetName <> "" Then
                Set ws = Worksheets.Add
                ws.Name = sheetName
                MsgBox "Sheet  & sheetName &  added successfully!"
            End If

        Case "RENAME"
            sheetName = InputBox("Enter current sheet name:")
            newName = InputBox("Enter new sheet name:")
            If sheetName <> "" And newName <> "" Then
                Worksheets(sheetName).Name = newName
                MsgBox "Sheet renamed successfully!"
            End If

        Case "DELETE"
            sheetName = InputBox("Enter sheet name to delete:")
            If sheetName <> "" Then
                If MsgBox("Delete sheet  & sheetName & ?", vbYesNo) = vbYes Then
                    Application.DisplayAlerts = False
                    Worksheets(sheetName).Delete
                    Application.DisplayAlerts = True
                    MsgBox "Sheet deleted successfully!"
                End If
            End If

        Case "ORGANIZE"
            ' Sort sheets alphabetically
            Dim i As Integer, j As Integer
            For i = 1 To Sheets.Count - 1
                For j = i + 1 To Sheets.Count
                    If Sheets(i).Name > Sheets(j).Name Then
                        Sheets(j).Move Before:=Sheets(i)
                    End If
                Next j
            Next i
            MsgBox "Sheets organised alphabetically!"
    End Select
End Sub

Related Topics

worksheets organisation management setup

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

Generate Custom VBA Code