{"id":53,"date":"2010-12-08T12:42:57","date_gmt":"2010-12-08T11:42:57","guid":{"rendered":"http:\/\/mariaevert.dk\/vba\/?p=53"},"modified":"2010-12-08T13:02:17","modified_gmt":"2010-12-08T12:02:17","slug":"vba-loop-through-sheets","status":"publish","type":"post","link":"https:\/\/mariaevert.dk\/vba\/?p=53","title":{"rendered":"VBA &#8211; Loop through sheets"},"content":{"rendered":"<p>This code snippet can be used if you want to loop thorugh the sheets in your workbook, either because you want to add something to everysheet, or &#8211; as in the example &#8211; you want to delete sheets with a specific name.  <\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSub slet_Faner()\r\nApplication.DisplayAlerts = False ' Makes it unnecessary for the user to approve the deletion\r\n\r\nDim ws As Worksheet\r\n   For Each ws In Worksheets\r\n           If ws.Name = &quot;Home&quot; Then ws.Delete 'Delete if name of sheet is &quot;Home&quot;\r\n    Next\r\n\r\nApplication.DisplayAlerts = True\r\nEnd Sub\r\n<\/pre>\n<p>Of course, if you want all sheets BUT the one sheet with a specific name, you just use: <\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nDim ws As Worksheet\r\n   For Each ws In Worksheets\r\n      If ws.Name &lt;&gt; &quot;Home&quot; Then ws.Delete 'Delete if name of sheet ISN'T &quot;Home&quot;\r\n    Next\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This code snippet can be used if you want to loop thorugh the sheets in your workbook, either because you want to add something to everysheet, or &#8211; as in the example &#8211; you want to delete sheets with a specific name. Of course, if you want all sheets BUT the one sheet with a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/53"}],"collection":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":5,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":62,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions\/62"}],"wp:attachment":[{"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariaevert.dk\/vba\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}