macro to delete rows caontaining specific data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,701
Office Version
  1. 2019
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
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

InfoH

Board Regular
Joined
Nov 1, 2011
Messages
60
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
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,111
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
 

howard

Well-known Member
Joined
Jun 26, 2006
Messages
5,701
Office Version
  1. 2019
Platform
  1. Windows
Thanks guys for the help, much appreciated
 

Watch MrExcel Video

Forum statistics

Threads
1,122,509
Messages
5,596,566
Members
414,078
Latest member
Frills

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
Top