简体   繁体   中英

I want delete all the rows that matches specific column value in excel using vba but facing error

Sub Delete_Rows()

Dim lo As ListObject 
Dim ActiveSheet As String
Dim wkbSource As Workbook

Application.ScreenUpdating = False

Set wkbSource = Workbooks.Open("C:\Users\nani\Desktop\11.0\deleteRows\abc.xlsx")

Set ActiveSheet = wkbSource.Sheets("LIST")

'perform delete

Set lo = ActiveSheet.ListOjects(1)

lo.Range.AutoFilter Field:=12, Criteria:="" Or "claimed"

Application.DisplayAlerts = False

lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete

Application.DisplayAlerts = True

wkbSource.Close SaveChanges:=True

End Sub

Some fixes:

Sub Delete_Rows()

Dim lo As ListObject 
Dim ws As Worksheet '<<<<<<
Dim wkbSource As Workbook

Application.ScreenUpdating = False

Set wkbSource = Workbooks.Open("C:\Users\nani\Desktop\11.0\deleteRows\abc.xlsx")

Set ws = wkbSource.Sheets("LIST")

Set lo = ws.ListObjects(1)  '<< typo

'fixed...
lo.Range.AutoFilter Field:=12, Criteria1 := "=", _
                           Operator := xlOr, _
                           Criteria2 := "claimed"

Application.DisplayAlerts = False

lo.DataBodyRange.SpecialCells(xlCellTypeVisible).Delete

Application.DisplayAlerts = True

wkbSource.Close SaveChanges:=True

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM