<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How Can I Delete All the Worksheets in a Spreadsheet Except for the First Worksheet?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/05/01/how-can-i-delete-all-the-worksheets-in-a-spreadsheet-except-for-the-first-worksheet.aspx</link><description>Hey, Scripting Guy! How can I delete all the worksheets in an Excel spreadsheet except for the first worksheet? -- NN 
 Hey, NN. Please excuse any bloodstains that might appear on your screen; as it turns out, the Scripting Guy who writes this column</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: How Can I Delete All the Worksheets in a Spreadsheet Except for the First Worksheet?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/05/01/how-can-i-delete-all-the-worksheets-in-a-spreadsheet-except-for-the-first-worksheet.aspx#3543895</link><pubDate>Thu, 03 Jan 2013 17:27:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3543895</guid><dc:creator>Christopher Woods (CustomMade)</dc:creator><description>&lt;p&gt;@mmoore5553 - an alternative way to think about the problem would be to select the sheet you want to keep (be that the last, the middle or whatever) then figure out the necessary VB code to reorder that worksheet to the first in the document, then run through the delete loop as normal.&lt;/p&gt;
&lt;p&gt;Otherwise you&amp;#39;d need to do something like this:&lt;/p&gt;
&lt;p&gt;Enumerate all worksheets. Show a list, offering radio buttons, checkboxes or a free text box (akin to the one in any Print dialog) allowing the user to enter the range, comma separated list of page numbers or a single worksheet page number they&amp;#39;d like to keep. Those pages would be saved from the deletion loop by being moved (in order?) to the front of the worksheet list, counted then subtracted from the grand total of worksheets in the documents - with the if loop iterating through until worksheets = the total number of sheets you specified to save.&lt;/p&gt;
&lt;p&gt;To delete all worksheets except specified, keeping all worksheets in-place without any reordering would require a more complex loop which was able to &amp;#39;know&amp;#39; which worksheet IDs it should exempt from the delete procedure. This depends on the functionality Excel offers through VB and whether you can even do something like an enumerate-once-delete-many; I suspect you&amp;#39;d have to work backwards in either case as the IDs likely internally decrement as the leftmost worksheet is deleted.&lt;/p&gt;
&lt;p&gt;Another way to attack that would possibly be to enumerate all the worksheets and grep the worksheet NAMES for each of them - then see if VB can delete by worksheet name, because we can see empirically that sheet names persist even if their internal IDs don&amp;#39;t.&lt;/p&gt;
&lt;p&gt;NB: IANA VB expert; the last time I wrote any VB was about 7 years ago in college so this is just thinking the problem through using coder logic. Perhaps this can be a bumper 2013 follow-on question for Scripting Guy!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3543895" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete All the Worksheets in a Spreadsheet Except for the First Worksheet?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/05/01/how-can-i-delete-all-the-worksheets-in-a-spreadsheet-except-for-the-first-worksheet.aspx#3540887</link><pubDate>Fri, 14 Dec 2012 15:04:56 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3540887</guid><dc:creator>mmoore5553</dc:creator><description>&lt;p&gt;What would we change to just delete all the rest except the last worksheet ? &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3540887" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete All the Worksheets in a Spreadsheet Except for the First Worksheet?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/05/01/how-can-i-delete-all-the-worksheets-in-a-spreadsheet-except-for-the-first-worksheet.aspx#3488033</link><pubDate>Thu, 22 Mar 2012 04:56:34 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3488033</guid><dc:creator>Jyotikrushna</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;nice work..thanks a lot to share this code&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3488033" width="1" height="1"&gt;</description></item><item><title>re: How Can I Delete All the Worksheets in a Spreadsheet Except for the First Worksheet?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/05/01/how-can-i-delete-all-the-worksheets-in-a-spreadsheet-except-for-the-first-worksheet.aspx#3369883</link><pubDate>Fri, 19 Nov 2010 16:44:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3369883</guid><dc:creator>Paul Damon</dc:creator><description>&lt;p&gt;Great story; &amp;nbsp;Based on your posting date, I trust that both the physical and psychological scars have healed by now!&lt;/p&gt;
&lt;p&gt;Oh yeah... very useful code too!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3369883" width="1" height="1"&gt;</description></item></channel></rss>