excel - vba select/remove all sheets except first -


i had problem removing unnecessary sheets. looked @ different forums , mashed different solutions.
macro removes sheets (except first sheet).

sub wrong()  dim sht object application.displayalerts = false     each sht in activeworkbook.sheets         if sht.index <> 1             sht.delete         end if     next  end sub 

is solution ok or can improved? tried actions directly on objects (workbooks, worksheets), failed each time

your code work (but have discovered yourself!)

you avoid if-then-end if looping through sheets index directly last 1 2nd one, follows

option explicit  sub wrong()     dim long      application.displayalerts = false     sheets '<--| reference active workbook 'sheets' collection         = .count 2 step -1 '<--| loop through referenced sheets index last 2nd             .item(i).delete '<--| delete current index sheet         next     end     application.displayalerts = true end sub 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -