Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello! I am new here.. have recently got into excel+vba. I have searched firs to see if I found an answer to my question.. but so far: nothing. S sorry if I just didn't search enough and this question has appeare before! I want to write a macro that selects all the sheets in a workboo EXCEPT the active one (which can be ANY of the sheets) and delete them, so I don't have to go manually and select them one by one. sometimes the files have just 3 sheets, but others they have over 40. This is what I wrote so far, Sub DeleteSheets() Dim a, i, NrWs as Integer a = Workbooks.Count NrWs = Worksheets.Count For i = 1 To NrWs Workbooks(a).Worksheets(i).Select ActiveWindow.SelectedSheets.Delete Next i End Sub When I run this macro, it deletes 3 of the sheets, but when it reache the 4th I get the following error: Run-Time Error '9': Subscript out of range So I don't know what to do from here :( Hope sb can help!! Thanks a lot! / ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to delete a 'Select Box' | Excel Discussion (Misc queries) | |||
Cannot select checkbox to delete it from a spreadsheet | Excel Discussion (Misc queries) | |||
Delete Select Targets | Excel Discussion (Misc queries) | |||
How to select a row to delete | Excel Programming | |||
Conditional Row Select and Delete | Excel Programming |