kaneda0149
Board Regular
- Joined
- Aug 4, 2009
- Messages
- 74
I found this fabulous VBA code that delete rows/shift up based on a certain text value. It works great when the cell contains only that specific value but when it's a cell that contains multiple string values and I want to delete based on part of the string in the value.
For example cell text value in column A: "Mickey Mouse Var. Rat"
I want to delete the rows, shift up if any text in column A has in it "Var. Rat". The code below does not work when there are other texts in the cell.
Thanks in advance!
For example cell text value in column A: "Mickey Mouse Var. Rat"
I want to delete the rows, shift up if any text in column A has in it "Var. Rat". The code below does not work when there are other texts in the cell.
Thanks in advance!
Code:
Sub DeleteSpecific_Rows()
' This macro deletes all rows on the active worksheet
' that have the following text in column A.
Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Value) = "Var. Rat" _
Or (cell.Value) = "VRDN" _
Or (cell.Value) = "NA" Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete
End Sub