Thank you for Visiting my Blog

Sunday, 7 May 2017

How to delete multiple worksheets in one click using Macro



Workbook Name : deletemultiplesheets.xlsm
Worksheet Name :Main
 
 I want to delete all the worksheets except worksheet "Main". Here is the solution  ...........
 Assign the below macro code to SUBMIT button . 


Sub deletemultiplesheets()
'--------------------- Delete multiple Worksheet in one click--------------------------


Dim wBook As Worksheet
Windows("deletemultiplesheets.xlsm").Activate
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    For Each wBook In Application.ActiveWorkbook.Worksheets
        If wBook.Name <> "Main" Then
       
        wBook.Delete
       
        End If
    Next
   
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
      
     
End Sub




No comments:

Post a Comment