Delete tabs whose names contain the same character

I get an extract from SAP where for each tab there is a sister tab with the same name followed by +. An example is PL1516and PL1516+. The last tab has nothing, and I just want to delete them. I tried this macro, but it does not work.

Option Explicit

Sub deleteSheets()
    Dim Sht As Worksheet
    For Each Sht In ActiveWorkbook.Worksheets
        If Sht.Name = "*+*" Then
            Sht.Delete
        End If
    Next Sht
End Sub
+4
source share
2 answers

Use the Like method to match characters.

Option Explicit

Sub deleteSheets()
    Dim Sht As Worksheet
    For Each Sht In ActiveWorkbook.Worksheets
        If Sht.Name Like "*+*" Then
            Sht.Delete
        End If
    Next Sht
End Sub
+6
source

Try changing this line If Sht.Name = "*+*" Thento If InStr(Sht.Name, "+") > 0 Then. It should work.

+6
source

Source: https://habr.com/ru/post/1651152/


All Articles