PDA

View Full Version : [SOLVED] Find word and delete else exit Sub



Pamella
08-02-2019, 02:56 AM
Trying to find a word and if not found then exit sub

Not sure if I can do it like this?


Sub DeleteRows()
Const WordToLook = "TESTING"
Dim RowWord As Long
Dim foundcell As Range


Set foundcell = (RowWord = Columns(1).Find(WordToLook, LookAt:=xlPart).Row)

If foundcell Is Nothing Then
Exit Sub

Else
Rows(RowWord + 5 & ":" & RowWord).Delete

end if
exit sub

Pamella
08-02-2019, 03:08 AM
Sub DeleteRows()
Const WordToLook = "TESTING"
Dim RowWord As range



Set RowWord = Columns(1).Find(WordToLook, LookAt:=xlPart)

If RowWord Is Nothing Then
Exit Sub

Else
Rows(RowWord.row + 5 & ":" & RowWord.row).Delete

end if
end sub

vcoolio
08-03-2019, 12:41 AM
Hello Pamella,

I noticed that you have marked the thread as solved. Does this mean that your code in post #2 works for you?

Cheerio,
vcoolio

Pamella
08-03-2019, 04:04 AM
Hi vcoolio, yes it does post #2