Conditionally delete entire row if cell value in column B is not starting with word "Transfer"

primala

New Member
Joined
May 31, 2012
Messages
39
Hi,

How to conditionally delete entire row if cell value in Column B is not starting with word "Transfer", regarding uppercase, lowercase or proper. Starting from row # 2?

The number of row reaching 20,000 lines in maximum.

Thanks in advance
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
See if this works (untested) on a copy of your sheet.
Code:
Sub DeleteIfNotTransfer()
Dim lR As Long, R As Range, vA As Variant, dRws As Range, i As Long
lR = Range("B" & Rows.Count).End(xlUp).Row
Set R = Range("B2:B" & lR)
vA = R.Value
For i = LBound(vA, 1) To UBound(vA, 1)
    If Not InStr(1, UCase(vA(i, 1)), "TRANSFER") = 1 Then
        If Not dRws Is Nothing Then
            Set dRws = Union(dRws, R.Cells(i))
        Else
            Set dRws = R.Cells(i)
        End If
    End If
Next i
Application.ScreenUpdating = False
If Not dRws Is Nothing Then dRws.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top