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
Post a Comment