Reputation: 11
I would like to delete paragraphs in Word document not containing the name of the country I am interested in. Based on the answer to another question on this site, I came up with:
Sub DeleteParagraphContainingString()
Dim search As String
search = "Afghan"
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
Dim txt As String
txt = para.Range.Text
If Not InStr(LCase(txt), search) Then
para.Range.Delete
End If
Next
End Sub
However, this deletes EVERY paragraph in the document. Can anyone tell me how to fix it?
Thanks! I do not know much about Word macros, as may be obvious from this question.
Upvotes: 1
Views: 119
Reputation: 3435
The problem is that the value you are searching for, "Afghan," has a capital 'A' in it, but you have changed the paragraph text to all lowercase. Change the value you are searching for to "afghan" with a lowercase 'a' and it should work.
Upvotes: 4