I'm trying to write an excel macro that will delete a row if the active cell in column B does not contain "21475". The follow is what I have written but when it's ran, it deletes all the rows. I would appreciate any and all help. Thanks in advance.
' This macro deletes all rows on the active worksheet
' that do not have 21475 in column B.
Dim rng As Range, cell As Range, del As Range
Dim strCellValue As String
Set rng = Intersect(Range("B:B"), ActiveSheet.UsedRange)
For Each cell In rng
strCellValue = (cell.Value)
If InStr(strSiteLink, "21475") = 0 Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
On Error Resume Next
0 · ·