{"id":3387,"date":"2021-06-03T10:22:47","date_gmt":"2021-06-03T17:22:47","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=3387"},"modified":"2021-06-03T10:22:48","modified_gmt":"2021-06-03T17:22:48","slug":"how-to-use-delete-method-of-worksheet-object-in-excel-vba","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=3387","title":{"rendered":"How to use Delete Method of Worksheet Object in Excel VBA"},"content":{"rendered":"\n<p>Delete Worksheet method in VBA is used to delete the sheet from the Excel workbook. When we delete a worksheet, Delete worksheet method displays a dialog box that reminds the user to confirm the deletion by default. If we click on Delete button on the dialog box then it deletes the worksheet from a workbook. It has Boolean value. That means dialog box will appear with two options. That is either Cancel(False) or Delete(True).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bm1\">Why we use Delete Worksheet method in VBA?<\/h3>\n\n\n\n<p>Sometimes we may don\u2019t want the some of the worksheets in a workbook. We may thought to delete those worksheets. During that time we can use Delete worksheet method to delete the worksheets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bm2\">VBA Delete Worksheet Method- Syntax<\/h3>\n\n\n\n<p>Here is the example syntax to Delete the Worksheet using VBA.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Worksheets(\u201cYourSheetName\u201d).Delete<\/p><\/blockquote>\n\n\n\n<p>Where Worksheet represents Object and&nbsp;<strong>Delete&nbsp;<\/strong>is the method of worksheet object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bm3\">VBA Delete Worksheet Method: Example 1<\/h3>\n\n\n\n<p>Please see the below VBA code to Delete Worksheet from a workbook with warning message. When we are deleting worksheet, it will display Excel dialog message and prompts the confirmation message to the user. Once you click on Delete button no more deleted sheet will be available in a workbook. If you click on cancel button, it won\u2019t delete the Worksheet in a workbook.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Sub Delete_Sheet()\n    Sheets(\"Sheet2\").Delete\n    \u2018Or\n    Sheet2.Delete\nEnd Sub\n<\/pre>\n\n\n\n<p>In the above example we have deleted sheet named \u2018Sheet2\u2019 from a workbook using Delete method of worksheet object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bm4\">VBA Delete Worksheet Method: Example 2<\/h3>\n\n\n\n<p>Please see the below VBA code to Delete active Worksheet from a workbook.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Sub Delete_ActiveSheet()\n    ActiveSheet.Delete\nEnd Sub\n<\/pre>\n\n\n\n<p>In the above example we have deleted active sheet from a workbook using Delete method of worksheet object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bm4\">VBA Delete Worksheet Method: Example 3<\/h3>\n\n\n\n<p>Please see the below VBA code to Delete Worksheet from a workbook without any warning message.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Sub Delete_Sheet_WithoutWarningMessage()\n    Application.DisplayAlerts = False\n    Sheets(\"Sheet2\").Delete\n    Application.DisplayAlerts = True\nEnd Sub\n<\/pre>\n\n\n\n<p>In the above example we have deleted Worksheet from a workbook using Delete method of worksheet object. And it will show you how to stop showing warning message while deleting worksheet.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"bm6\">VBA Delete Worksheet Method \u2013 Instructions<\/h3>\n\n\n\n<p>Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Open an Excel Worksheet<\/li><li>Press Alt+F11 to Open the VBA Editor window or Open it from the Developer Tab<\/li><li>Insert a Module from Insert Menu<\/li><li>Copy the above code for activating worksheet and Paste in the code window(VBA Editor)<\/li><li>Save the file as macro enabled Worksheet<\/li><li>Press \u2018F5\u2019 to run it or Keep Pressing \u2018F8\u2019 to debug the code line by line and then check deleted Worksheet doesnot exist in the Workbook..<\/li><\/ol>\n\n\n\n<p>Ref: https:\/\/analysistabs.com\/vba-code\/worksheet\/m\/delete\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delete Worksheet method in VBA is used to delete the sheet from the Excel workbook. When we delete a worksheet, Delete worksheet method displays a dialog box that reminds the user to confirm the deletion by default. If we click on Delete button on the dialog box then it deletes the worksheet from a workbook. <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=3387\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,18],"tags":[755],"class_list":["post-3387","post","type-post","status-publish","format-standard","hentry","category-microsoft","category-microsoft-office","tag-delete-method-vba"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3387"}],"version-history":[{"count":1,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3387\/revisions"}],"predecessor-version":[{"id":3388,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/3387\/revisions\/3388"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}