macro to delete rows caontaining specific data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,115
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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

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
11,726
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
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
6,115
Office Version
  1. 2021
Platform
  1. Windows
Thanks guys for the help, much appreciated
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
11,726
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Glad to help. :)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,148
Messages
5,835,678
Members
430,374
Latest member
PeteBrown

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