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
And just debugged:
Arr(i) = <Subscript out of range>
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>