VBA: Deleting rows after 2 columns have been filtered.

TitoBurrito

New Member
Joined
Oct 27, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hello,

After research and trial and error I am unable to get this to work.

Here is my code:

With Sheet2.Range("A1:BM1")
.AutoFilter Field:=13, Criteria1:="*EMEA*", Operator:=xlOr, Criteria2:="*Oceania*"
.AutoFilter Field:=42, Criteria1:="="
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
End With
Sheet2.AutoFilterMode = False

I am trying to filter column 13 with criteria and column 42 for blanks, then delete all the rows that that are populated.
The filtering is working. The deleting of the rows is the problem.
I am getting Run-time error 1004: Application-defined or object-defined error. With the .OFFSET(1,0) ROW BEING HIGHLIGHTED.

Any help would be lovely,
Thank You
 
Thought I would throw my 2 cents worth into the mix. Contrary to popular belief, you don't have to select .SpecialCells(xlCellTypeVisible) when deleting rows using the Autofilter method. Consider the following:
VBA Code:
Sub Delete_No_Special_Cells()
    With Sheet2.Range("A1").CurrentRegion
        .AutoFilter 13, "*EMEA*", 2, "*Oceania*"
        .AutoFilter 42, "="
        If .Cells(Rows.Count, 1).End(xlUp).Row > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete '<~~ no special cells selected
        End If
        .AutoFilter
    End With
End Sub
Test it & you should find it works without selecting xlCellTypeVisible
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,214,891
Messages
6,122,101
Members
449,066
Latest member
Andyg666

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