VBA Filter and Delete Rows Errors On Row Delete

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
Hello all. The second code set is based this thread:
HTML:
https://www.mrexcel.com/forum/excel-questions/553208-vba-filter-delete.html
though I've tried other suggstions and get the same result. An error on line 26.

Arggg . . . ideas

TIA

Ron

Code:
 1 Sub A5_tm_Filter() 2    'Application.DisplayAlerts = False
 3    'Application.DisplayStatusBar = False
 4    'Application.ScreenUpdating = False
 5'
 6    Dim thiswb                              As Workbook
 7    Dim thisws                              As Worksheet
 8    Dim LastRow                             As Long
 9    Dim lastCol                             As Integer
10    Dim rng                                 As Range
11'
12    Set thiswb = ActiveWorkbook
13    Set thisws = ActiveSheet
14    '
15    LastRow = Cells(Cells.Rows.Count, "F").End(xlUp).Row
16    lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
17    '
18    If ActiveSheet.FilterMode = True Then
19        ActiveSheet.ShowAllData
20    End If
21'
22    Range("A1").Activate
23    With Range("A1", Cells(LastRow, lastCol))
24        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilter.Range.AutoFilter
25        .AutoFilter field:=2, Criteria1:="="
26        Range("A2" & Cells(LastRow, lastCol)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
27        .AutoFilter
28    End With
29    End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try substituting this
Code:
With Range("A1", Cells(LastRow, lastCol))
24        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilter.Range.AutoFilter
25        .AutoFilter field:=2, Criteria1:="="
With this
Code:
ActiveSheet.AutoFilterMode = False
With Range("A1", Cells(LastRow, lastCol))
.AutoFilter field:=2, Criteria1:="="

Also modify the next line to

Code:
Range("A2", Cells(LastRow, lastCol)).SpecialCells(xlCellTypeVisible).EntireRow.Delete
 
Last edited:
Upvote 0
Thank you! And with much thanks to the years of others assistance on using this site, I can at least understand what you did though obviously not skilled enough to see the error the first time.

Ron
 
Upvote 0
Thank you! And with much thanks to the years of others assistance on using this site, I can at least understand what you did though obviously not skilled enough to see the error the first time.

Ron
You're Welcome,
regards, JLG
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,094
Latest member
bsb1122

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