macro to delete rows caontaining specific data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro to delete rows containing text for eg demo/Fleet , fleet cars, New Dept in Col V on sheet "used cars"


eh BR1 Demo/Fleet

BR1 New Dept

Br2 Fleet cars etc



However when running the macro, no rows are being deleted


It would be appreciated if someone can kindly assist me


Code:
 Sub Delete_Demo()
Sheets("Used Vehicles").Select

Dim LR As Long, I As Long

LR = Cells(Rows.Count, "V").End(xlUp).Row 'last row
    For I = LR To 1 Step -1
           If Cells(I, "V") Like "*Demo*" Then Rows(I).Delete
            If Cells(I, "V") Like "*Fleet*" Then Rows(I).Delete
   If Cells(I, "V") like  "*New dept*" Then Rows(I).Delete
    Next I


End Sub


Possibly I need to use Instr, but not sure how to use this
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
you could always have a macro setup to perform a filter on those columns with that data, then select and delete rows which are visible
then unfilter and turn screen updating back on..

probably a smarter way to do it but that way will work
 
Upvote 0
try:
Code:
Sub Delete_Demo()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Range("V" & Rows.Count).End(xlUp).Row
    Dim I As Long
    For I = LastRow To 1 Step -1
        If Sheets("Used Vehicles").Cells(I, "V") Like "*Demo*" Or Cells(I, "V") Like "*Fleet*" Or Cells(I, "V") Like "*New dept*" Then
            Rows(I).EntireRow.Delete
        End If
    Next I
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks guys for the help, much appreciated
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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