AutoFilter method of range class failed

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello, I am trying to delete whole row.
If any cell in column A on sheet1 contains a value from sheet2 column P
But for some reason I get error 1004

Can anyone help me please? Where I did a mistake?

Error line
Code:
.AutoFilter 1, Array(Arr), 7

VBA Code:
    Dim wb As Workbook
    Dim ws As Worksheet, Arr, i As Long
    Dim LR As Long
    Set wb = ThisWorkbook
    Set ws = wb.Sheets("Sheet1")
    Set sh = wb.Sheets("Sheet2")
    Application.ScreenUpdating = False
   
    ws.Activate
    LR = Cells(Rows.Count, 16).End(xlUp).Row
   
    Arr = ws.Range("P2:P" & LR).Value
    Arr = Application.Transpose(Application.Index(Arr, 0, 1))
   
    For i = LBound(Arr) To UBound(Arr)
        Arr(i) = CStr(Arr(i))
    Next i
   
    sh.Activate
    With sh.Range("A3:A2000")
        .AutoFilter 1, Array(Arr), 7
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
        .AutoFilter
    End With

And just debugged:
Arr(i) = <Subscript out of range>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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