I'm getting the Next without For error when trying to run the below macro. For some background, I want to search A1 of every worksheet to see if it contains the text string "- Placeholder" using the wildcard. If the worksheet contains that text string, I want to delete the worksheet. Appreciate any assistance and thanks in advance!
Sub deletesheetbycell()
'Delete Worksheets
Dim shName As String
Dim xName As String
Dim xWs As Worksheet
Dim cnt As Integer
Dim strName As String
Dim blnResult As Boolean
strName = "- Placeholder"
For Each xWs In ThisWorkbook.Sheets
With xWs.Range("A1")
If strName Like "*" & "- Placeholder" & "*" Then
blnResult = True
Else
blnResult = False
End If
If blnResult = True Then
xWs.Delete
cnt = cnt + 1
End If
Next xWs
Application.DisplayAlerts = True
End Sub
Sub deletesheetbycell()
'Delete Worksheets
Dim shName As String
Dim xName As String
Dim xWs As Worksheet
Dim cnt As Integer
Dim strName As String
Dim blnResult As Boolean
strName = "- Placeholder"
For Each xWs In ThisWorkbook.Sheets
With xWs.Range("A1")
If strName Like "*" & "- Placeholder" & "*" Then
blnResult = True
Else
blnResult = False
End If
If blnResult = True Then
xWs.Delete
cnt = cnt + 1
End If
Next xWs
Application.DisplayAlerts = True
End Sub