If the words occur many times in the Column then you would need to continue searching the column for any other rows that contain the word. Arlette's code works well if there is a single occurence of the word however if it appears many times then if would not delete all the rows. For interests sake the following will search for ALL occurences of the works, sorts the array with the rows numbers using a bubble sort then deletes the rows. It involves more code simply because it is looking for e.g. the word Apple being in column A 5 times.
Option Explicit
Sub setRNG()
Dim fCell As Range, lCell As Range, fAdd As String, a
Dim wdSrch, keyWd As String, k As Long, nCell As Range, x As Long
Dim First As Integer, last As Integer, i As Integer, j As Integer, temp As Long
ReDim a(x)
With Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
Set lCell = .Cells(.Cells.Count)
End With
wdSrch = Array("ee", "People", "Orange", "Toast", "Total", "Apple", "Race", "Many", "Pear", "Lost")
For k = LBound(wdSrch) To UBound(wdSrch)
keyWd = CStr(wdSrch(k))
Set fCell = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Find(what:=keyWd, after:=lCell)
If Not fCell Is Nothing Then
fAdd = fCell.Address
End If
Do Until fCell Is Nothing
ReDim Preserve a(x)
a(x) = fCell.Row
x = x + 1
Set fCell = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).FindNext(after:=fCell)
If fCell.Address = fAdd Then
Exit Do
End If
Loop
Next
For i = LBound(a) To UBound(a) - 1
For j = i + 1 To UBound(a)
If a(i) > a(j) Then
temp = a(j)
a(j) = a(i)
a(i) = temp
End If
Next j
Next i
For k = UBound(a) To LBound(a) Step -1
Rows(a(k)).EntireRow.Delete Shift:=xlUp
Next
End Sub
Anthony
“Confidence never comes from having all the answers; it comes from being open to all the questions.”
PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
Bookmarks