How to Delete a Worksheet with No Prompt Using Excel VBA (5 Methods)

 

What Is a Prompt Warning Message?

The following VBA code creates a new Excel worksheet and deletes it when you run the code.

Sub SheetEraser()
ActiveSheet.Delete
End Sub

The above VBA code deletes the active worksheet. But before deleting a worksheet, it will show a pop-up warning message regarding the sheet deletion, like the following screenshot.

What is a Prompt Warning Message?


How to Delete a Worksheet with No Prompt Using Excel VBA: 5 Methods

Method 1 – Delete a Single Worksheet with No Prompt Using Excel VBA

  • Press Alt + F11 to open the VBA editor.
  • Create a new module by going to Insert and choosing Module.

  • Copy the following VBA code.
Sub SheetEraser()
Application.DisplayAlerts = False
Sheets("Sheet7").Delete
Application.DisplayAlerts = True
End Sub
  • Paste and save the above code in the VBA code editor.

Delete a Single Worksheet with No Prompt Using the Excel VBA

  • Go to the Developer tab.
  • From the Code group, select Macros.

  • This will open the Macro window. You can also press Alt + F8 to open the Macro dialog box.
  • From the Macro dialog box, select the function name of the VBA code and hit Run.

  • This will instantly delete the sheet you inserted in the VBA code without showing any prompt warning message.

Method 2 – Delete an Active Worksheet with No Prompt Using Excel VBA

  • Press Alt + F11 to open the VBA editor.
  • Go to Insert and select Module.

  • Copy the following VBA code.
Sub SheetEraser()
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
End Sub
  • Paste the code in the VBA editor and save it.

Delete an Active Worksheet with No Prompt Using the Excel VBA

  • Press the Alt + F8 buttons to open the Macro dialog box.
  • Select the function name and hit the Run button.

  • This will instantly delete the active worksheet without showing any prompt warning box.

Method 3 – Delete Multiple Worksheets with No Prompt Using Excel VBA

  • Hit Alt + F11 to open the VBA editor.
  • Go to Insert and select Module.

  • Copy the following VBA code:
Option Explicit
Sub DeleteSheets()
Dim x As Long
Application.DisplayAlerts = False
For x = 1 To Worksheets.Count
If Worksheets(x).Name Like "Sample *" Then Worksheets(x).Delete
Next x
Application.DisplayAlerts = True
End Sub
  • Paste and save the above code in the VBA editor.

Delete Multiple Worksheets with No Prompt Using the Excel VBA

  • Press Alt + F8 to open the Macro window.
  • Select the function name from the Macro dialog box and hit the Run button.

  • This will delete all the sheets started with the “Sample” keyword without showing any prompt warning box.

Method 4 – Pick a Worksheet to Delete with No Prompt Using Excel VBA

  • Press Alt + F11 to open the VBA editor.
  • Click on the Module from the Insert tab.

  • Copy the following VBA code:
Sub CheckThenDelete()
Dim x As Worksheet
Dim y As Variant
y = InputBox("Enter a Sheet Name to Delete: ")
Application.DisplayAlerts = False
For Each x In ThisWorkbook.Worksheets
If y = x.Name Then
x.Delete
End If
Next x
Application.DisplayAlerts = True
End Sub
  • Paste and save the code in the VBA editor.

Pickup a Worksheet to Delete with No Prompt Using Excel VBA

  • Press F5 to run the code.
  • Insert a worksheet name that you want to delete in the pop-up dialog box.
  • Hit the OK button to delete the sheet.

Read More: Excel VBA: Delete Sheet If It Exists


Method 5 – Delete All the Worksheets Using the Excel VBA with No Prompt Warning Box

  • Hit the Alt + F11 keys to open the VBA editor.
  • Go to Insert and choose Module.

  • Copy the following VBA code:
Sub AllSheetsEraser()
Dim x As Worksheet
Dim y As String
y = "BlankSheet-" & Format(Now, "SS")
Sheets.Add.Name = y
Application.DisplayAlerts = False
For Each x In ThisWorkbook.Worksheets
If x.Name <> y Then
x.Delete
End If
Next x
Application.DisplayAlerts = True
End Sub
  • Press Ctrl + V to paste and press Ctrl+ S to save to VBA code in the VBA editor.

Delete All the Worksheets Using the Excel VBA with No Prompt Warning Box

  • Hit the F5 button to run the code.
  • This will delete all the worksheets in the active workbook without showing any prompt box.

Things to Remember

  • Press Alt + F11 to open the VBA editor.
  • To run VBA code, press the F5 button.
  • You can press Alt + F8 to open the Macro window.

Download the Practice Workbook

 

Get FREE Advanced Excel Exercises with Solutions!
Mrinmoy Roy
Mrinmoy Roy

Mrinmoy Roy, a dedicated professional with a BSc in Electronics and Communication Engineering from Khulna University of Engineering & Technology, Bangladesh, brings over two years of expertise to the ExcelDemy project. As a prolific contributor, he has authored around 180 articles, showcasing his deep knowledge and passion for Microsoft Excel, Data Analysis, and VBA. His unwavering commitment to continuous learning, combined with versatile skills, renders him well-suited for roles in data management and spreadsheet solutions. He has interest... Read Full Bio

2 Comments
  1. master….
    ini ada macro untuk mengconvert menjadi value untuk 1 sheet saja.
    bagaimana caranya untuk convert value untuk semua sheet yang ada (workbook)
    ‘This code will convert all formulas into values
    Sub ConvertToValues()
    With ActiveSheet.UsedRange
    .Value = .Value
    End With
    End Sub

    • Thank you LUBIS for reaching us out. You can run the following VBA code to convert all formulas into values across all the sheets in the workbook.

      Sub ConvertToValues()
      For Each ws In Worksheets
      With ws.UsedRange
      .Value = .Value
      End With
      Next
      End Sub

      This code utilizes a “For Each” loop to iterate through each worksheet in the workbook.

      Regards
      Aniruddah
      Exceldemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo