To run the VBA, first you will need to do the following.
- Under the Developer tab, click the Visual Basic option.
- On the insert option in the menu and click the module
- Enter the code and run it.
To delete a worksheet in excel VBA, you can use the delete command. There are different ways in which can delete the worksheet in Excel.
Delete Worksheet by Name
To Delete Worksheet by Name
Delete Worksheet by Index Number
To Delete Worksheet by Index Number
Here, 1 represents the index number of the sheets. To delete the last worksheet in the workbook
Delete Worksheet Without Prompt
You can disable the prompts while deleting the worksheets. You can do this by toggling DisplayAlerts:
Application.DisplayAlerts = False Sheets("Sheet1").Delete Application.DisplayAlerts = True
You can see that the worksheet gets deleted without a prompt.
Clear Sheet in Excel VBA
To clear sheet in Excel VBA, you can use the clear command
To clear the Activesheet’s cells of all cell properties: contents, formats, comments, etc
To clear only the cell contents
To clear only the cell formats
Clear Sheet (By Name)
To clear a specific worksheet
Enter your email address to subscribe to this blog and receive notifications of new posts by email.