Delete rows in each workbook based on keyword match specific column

satish78

Board Regular
Joined
Aug 31, 2014
Messages
218
Hi Friends,

I looked in to forum posts where I am looking to delete rows with keyword match in specific column(like ColumnI) in multiple workbooks in a folder.
I want use VBA to delete entire row of each workbook in folder (there are 100+ workbooks in a folder) based on keyword match(keyword is "incomplete") in ColumnI.
Vba should loop through list of workbooks in a folder.

Thanks
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Does each workbook have more than one sheet in which you want to delete rows? Are you looking at column L or column i ? What is the full path to the folder where the files are saved? What is the extension of the files (xlsx, xlsm)? Are those files the only files in that folder?
 
Upvote 0
Each workbook have only one sheet.
Looking at Column i.
Files exists in folder path F:\Records
We can save files in folder path F:\Uniquerecords
Extension of files .csv
they are only files in that folder.
 
Upvote 0
Place this macro in a new workbook and run it from there.
VBA Code:
Sub DeleteRows()
    Application.ScreenUpdating = False
    Dim srcWB As Workbook
    Const strPath As String = "F:\Records\"
    ChDir strPath
    strExtension = Dir(strPath & "*.csv")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        With Range("A1").CurrentRegion
            .AutoFilter 9, "incomplete"
            .AutoFilter.Range.Offset(1).EntireRow.Delete
            Range("A1").AutoFilter
        End With
        Application.DisplayAlerts = False
        srcWB.SaveAs Filename:="F:\Uniquerecords\" & srcWB.Name, FileFormat:=xlCSV, CreateBackup:=False
        Application.DisplayAlerts = True
        srcWB.Close False
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I am getting run-time error 424.
Object required at
.AutoFilter.Range.Offset(1).EntireRow.Delete
 
Upvote 0
Try:
VBA Code:
Sub DeleteRows()
    Application.ScreenUpdating = False
    Dim srcWB As Workbook
    Const strPath As String = "F:\Records\"
    ChDir strPath
    strExtension = Dir(strPath & "*.csv")
    Do While strExtension <> ""
        Set srcWB = Workbooks.Open(strPath & strExtension)
        With Range("A1")
            .CurrentRegion.AutoFilter 9, "incomplete"
            .AutoFilter.Range.Offset(1).EntireRow.Delete
            Range("A1").AutoFilter
        End With
        Application.DisplayAlerts = False
        srcWB.SaveAs Filename:="F:\Uniquerecords\" & srcWB.Name, FileFormat:=xlCSV, CreateBackup:=False
        Application.DisplayAlerts = True
        srcWB.Close False
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
same error.
I just changed the path directory.
 

Attachments

  • autofilter.jpg
    autofilter.jpg
    179.6 KB · Views: 4
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your csv sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Here is the data
I want to delete rows which has Incomplete in Columni

Book1
ABCDEFGHI
1First_nameLast_nameMiddle_nameJob_TitleCompanyURLDescriptionDateStatus
2LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewWed, 20 Jan 2021 18:13:00 GMTcomplete
3LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewFri, 29 Jan 2021 23:10:00 GMTcomplete
4LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewSun, 28 Jun 2020 09:03:00 GMTcomplete
5LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewMon, 04 Nov 2019 14:13:00 GMTcomplete
6LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewWed, 08 Jul 2020 22:20:00 GMTIncomplete
7LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewTue, 28 Jan 2020 06:41:00 GMTcomplete
8LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewWed, 02 Dec 2020 18:14:00 GMTcomplete
9LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewFri, 22 Nov 2019 00:44:00 GMTcomplete
10LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewTue, 02 Feb 2021 11:17:00 GMTIncomplete
11LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewWed, 06 Nov 2019 01:03:00 GMTcomplete
12LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewTue, 05 Nov 2019 00:43:00 GMTcomplete
13LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewSat, 02 Nov 2019 15:20:00 GMTIncomplete
14LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewFri, 01 Nov 2019 00:40:00 GMTcomplete
15LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewThu, 12 Nov 2020 18:52:00 GMTIncomplete
16LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewThu, 31 Oct 2019 07:29:00 GMTIncomplete
17LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewMon, 11 Nov 2019 22:11:00 GMTIncomplete
18LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewSat, 10 Oct 2020 11:25:00 GMTIncomplete
19LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewSun, 23 Aug 2020 06:02:00 GMTIncomplete
20LockwoodMcKennaVillanova UniversitySan Francisco Bay Areahttps://www.example.comviewThu, 04 Feb 2021 04:27:00 GMTcomplete
Sheet1
 
Upvote 0
Try:
VBA Code:
 Sub DeleteRows() Application.ScreenUpdating = False Dim srcWB As Workbook Const strPath As String = "F:\Records\" ChDir strPath strExtension = Dir(strPath & "*.csv") Do While strExtension <> "" Set srcWB = Workbooks.Open(strPath & strExtension) With Range("A1") .CurrentRegion.AutoFilter 9, "incomplete" .AutoFilter.Range.Offset(1).EntireRow.Delete Range("A1").AutoFilter End With Application.DisplayAlerts = False srcWB.SaveAs Filename:="F:\Uniquerecords\" & srcWB.Name, FileFormat:=xlCSV, CreateBackup:=False Application.DisplayAlerts = True srcWB.Close False Loop Application.ScreenUpdating = True End Sub

I posted minisheet.
there is some error in vba code at autofilter.
Did you recheck that?.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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