EntireRow.Delete not working

morsagmon

New Member
Joined
May 6, 2015
Messages
28
Hi.

I need to delete rows from a ListObject very fast, based on criteria applied on a date column.

I get the 1004 Delete method of Range class failed error on the EntireRow.Delete line:


Code:
Sub DeleteOldPhoneCalls(ByRef tblCalls As ListObject)
    
    Dim rngDelete As Range

    tblCalls.Range.AutoFilter Field:=1, Criteria1:="<" & Now() - Range("Days_to_Keep_Phone_Calls").Value
    Set rngDelete = tblCalls.Range.SpecialCells(xlCellTypeVisible)
    tblCalls.Range.AutoFilter

    If Not rngDelete Is Nothing Then rngDelete.EntireRow.Delete

    Set rngDelete = Nothing
End Sub


First column of this table is of type Date and has valid dates in it.

Here's how I call this sub:

Code:
Dim tblCalls As ListObject
Set tblCalls = Sheets("Calls Table").ListObjects("PhoneCallsTable")
Call DeleteOldPhoneCalls(tblCalls)


Any ideas?
Thanks!
 
Hi,

My first assumption would be to replace ...Now() by Date ....

HTH
 
Upvote 0
This is what works eventually:
Code:
Sub DeleteOldPhoneCalls(ByRef tblCalls As ListObject)

    Dim rngDelete As Range
    
    Range(tblCalls).Select
    tblCalls.Range.AutoFilter Field:=1, Criteria1:="<" & Date - Range("Days_to_Keep_Phone_Calls").Value
    On Error GoTo CloseSub
    Set rngDelete = Selection.SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    Selection.AutoFilter
    If Not rngDelete Is Nothing Then rngDelete.Delete
    

CloseSub:
    tblCalls.Range.AutoFilter Field:=1
    Set rngDelete = Nothing
End Sub


Thanks!
Mor
 
Upvote 0
Glad you have managed to solve your problem ...

Thanks for your thanks ...;)
 
Upvote 0

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