Hi there!
I have this code, but it only works for the 2nd and 3rd conditions. How do I add an “OR” condition to it that searches the entire workbook for a partial text and delete the worksheet if found? For example, merged cell A1:C1 = “Your one stop for Excel tips & solutions”, but I only need to find “tips & solutions” and delete any sheet that contains this phrase. Thanks in advance!
So to summarize, the goal is to delete sheets if A5 = 100 AND A6 = 1 OR A1 = “* tips & solutions” but code can’t find partial text with the wildcard symbol.
I have this code, but it only works for the 2nd and 3rd conditions. How do I add an “OR” condition to it that searches the entire workbook for a partial text and delete the worksheet if found? For example, merged cell A1:C1 = “Your one stop for Excel tips & solutions”, but I only need to find “tips & solutions” and delete any sheet that contains this phrase. Thanks in advance!
So to summarize, the goal is to delete sheets if A5 = 100 AND A6 = 1 OR A1 = “* tips & solutions” but code can’t find partial text with the wildcard symbol.
VBA Code:
Sub Delete_Worksheets
Dim ws As Worksheet
Dim i As integer
Application.DisplayAlerts = False
For each ws in ActiveWorkbook.Worksheets
If ws.range(“A1”).Value = “* tips & solutions” Or ws.range(“A5”).Value = 100 And ws.range(“A6”) = 1 Then
On Error Resume Next
ws.delete
On Error GoTo 0
End If
Next
Application.DisplayAlerts = True
End Sub