Sheet Delete

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,062
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code is working all perfect, but only change is need that it will take the sheet name from the range and range will be till the end of the records.

VBA Code:
Dim ws As Worksheet
    Application.DisplayAlerts = False   'Optional
  
    For Each ws In Worksheets
        Select Case ws.Name
            'Include sheet names to keep on next line (with comma between)
            Case Sheets("Report").Range("a1").Value, Sheets("Report").Range("a2").Value
                    ' Modify to check the sheet name till the end of the row
                'Do nothing
            Case Else
                ws.Delete
        End Select
    Next ws

    Application.DisplayAlerts = True
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi got the solution

VBA Code:
Private Sub CommandButton4_Click()
    Dim i As Long
    Dim cnt As Long
    Dim xWb, actWs As Worksheet
    Set actWs = ThisWorkbook.Worksheets("Report")
    cnt = 0
    Application.DisplayAlerts = False
    
    For i = Sheets.Count To 1 Step -1
        If Not ThisWorkbook.Sheets(i) Is actWs Then
            xWb = Application.Match(Sheets(i).Name, actWs.Range("A1:A15"), 0)
            If IsError(xWb) Then
                ThisWorkbook.Sheets(i).Delete
                cnt = cnt + 1
            End If
        End If
    Next
    Application.DisplayAlerts = True
    If cnt = 0 Then
        MsgBox "Not find the sheets to be seleted", vbInformation, "Data"
    Else
        MsgBox "Have deleted" & cnt & "worksheets"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,641
Messages
6,125,981
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top