Delete Worksheet Using Excel VBA | Excel VBA Automation

Delete Worksheet
  • Save

Introduction/Problem Statement/Business Need:

This article is to Delete Worksheet in a workbook using Excel VBA code.

In many cases, the user wants to delete the worksheet without manual intervention.


Delete Worksheet:

This code will delete a worksheet by its name.

Delete Worksheet
  • Save

Sub KDataScience_DeleteWorksheetByName()

    'Delete Sheet By giving Sheet Name in Double Quotes

End Sub

This code will delete a worksheet by Index number.

delete worksheet by Index number
  • Save

Sub KDataScience_DeleteWorksheetByIndexNumber()

    'Delete Sheet by giving Index Number

End Sub

This code will delete the last worksheet in the workbook.

delete the last woksheet
  • Save

Sub KDataScience_DeleteLastWorksheet()

    'Delete Last Sheet in workbook.

End Sub

Delete Worksheet Without Deleting Prompt:

Deleting prompt has been shown in below screenshot :

Delete Worksheet Without Deleting Prompt
  • Save

This code will delete sheets without deleting prompt:

delete sheets without deleting prompt
  • Save

Sub KDataScience_DeleteSheetsWithoutDeletingPrompt()

    ' "Application.displayalerts" restrict the prompt msg.
    Application.DisplayAlerts = False
    Application.DisplayAlerts = True

End Sub

This code will delete the “Data” sheet if it exists:

code will delete
  • Save

Sub KDataScience_DeleteSheetsIfExists()

    Dim Iloop%
    Application.DisplayAlerts = False
        For Iloop = Worksheets.Count To 0 Step -1
            If ThisWorkbook.Worksheets(Iloop).Name = "Data" Then
            End If
    Application.DisplayAlerts = True

End Sub


If you want to delete worksheet in a workbook then you may use any of the above code instead of manually doing it. KDataScience would prefer you to use code to delete the sheet without “Deleting” Prompt.

Don't miss out!
Subscribe To Newsletter

Get the latest Excel, VBA, Automation, Tips & Tricks, delivered straight to your inbox.

Invalid email address
Give it a try. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap