rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 569
- Office Version
- 365
- Platform
- Windows
I have a sheet that my macro searches in colA for a specific text. I want to delete rows but only in instances where the actual text string was found. I am running into an Error Type 91, and I know it is because the search string did not turn up any results, and when I assigned those "non-results" to a term "PDARow" and then use that term in an IF Then statement, it fails. I would like to assign some text to the term "PDARow" when the search results are nothing (say "notext"). That way I can write If PDARow.value = "notext" then and the macro should work fine. How do I make this assignment when the search results on nothing?
Thanks for the help.
VBA Code:
Dim PDARow As Range
Dim MISCRow As Range
With Sheets("Component List")
Set PDARow = .Range("A:A").Find(What:="PROCESS DEVELOPMENT ASSISTANCE (per hour)", LookIn:=xlValues)
End With
With Sheets("Component List")
Set MISCRow = .Range("A:A").Find(What:="MISCELLANEOUS", LookIn:=xlValues)
End With
If MISCRow.Value = "" Then 'place "notext" here to fix error 91
If PDARow.Value = "" Then 'place "notext" here to fix error 91
Sheets("Component List").Rows(ATISRow.Row & ":" & newLrow - 1).EntireRow.Delete
Else
Sheets("Component List").Rows(PDARow.Row & ":" & newLrow - 1).EntireRow.Delete
End If
Else
If PDARow.Value = "" Then 'place "notext" here to fix error 91
Sheets("Component List").Rows(ATISRow.Row & ":" & newLrow - 1).EntireRow.Delete
Else
Sheets("Component List").Rows(PDARow.Row & ":" & MISCRow.Row - 1).EntireRow.Delete
End If
End If
Thanks for the help.