Here ya go:
Private Sub DeleteFails()
Dim i As Long
Dim booFound As Boolean
Dim cel As Range, rng As Range
Set rng = ThisWorkbook.Worksheets(1).Range("A1:D100") 'set to whatever your range is.
On Error Resume Next 'for when the text is not found.
Err.Clear
'check columns first:
For i = rng.Columns.Count To 1 Step -1
Set cel = rng.Columns(i).Find(what:="Fail", LookIn:=xlValues, lookat:=xlWhole)
If cel Is Nothing Then rng.Columns(i).Delete
Next i
'then rows:
For i = rng.Rows.Count To 1 Step -1
Set cel = rng.Rows(i).Find(what:="Fail", LookIn:=xlValues, lookat:=xlWhole)
If cel Is Nothing Then rng.Rows(i).Delete
Next i
On Error GoTo 0
Err.Clear
End Sub
If you want to search for anything containing "fail" but not necessarily the whole word - e.g. failure, or failed etc - use this in the search:
Set cel = rng.Columns(i).Find(what:="Fail", LookIn:=xlValues, lookat:=xlPart)
Hope that helps.
Bookmarks