Macro to remove all rows that contain the word "sale"

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have a sheet called "Raw Data"
I'd like a macro that can find ever instance of the word "Sale" and delete the entire row.
now i need it to be "sale" anytime, so if there's salesman it deletes the row, the range is "A2 to DA" and last row

please help if you can thanks
Tony
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Code:
Option Explicit

Option Compare Text
Sub Foo()
    Application.ScreenUpdating = False
    Dim c As Range, rng As Range
    Dim lr As Long, r As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row   'This assumes Column has last row
    Set rng = Range("A2:DA" & lr)                'Change this to your actual range you wish to scan
    For Each c In rng
        If InStr(c, "sale") > 0 Then
            r = c.Row
            Range("A" & r).EntireRow.Delete
        End If
    Next c
    Application.ScreenUpdating = True
    MsgBox "completed"
End Sub
 
Upvote 0
Solution
Hi!

I'm wondering if there a VBA for this to remove entire word that have multiple values. For example, I would like to remove rows that contain the word "sale" and "bow"?

Thank you!

excelnovicesir
 
Upvote 0
Change this line:

VBA Code:
If InStr(c, "sale") > 0 Then

to:

VBA Code:
If InStr(c, "sale") > 0 AND InStr(c, "bow") > 0 Then
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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