I'm trying to in Excel VBA create a macro that can take the data and filter them to a certain criteria. Then copy the filtered table into another spreadsheet. I've tried to do it by myself but have run into a roadblock.
The exact problem is shows me is Run time error"1004" where it says it cant be applied to a selected range? Which i dont understand what it means. The code error is shown to be at the filter part where the selection. Autofilter is.
I would greatly appreciate any tips, pointer or help to finish this VBA coding
The code i'm having problems with is the one below
Sub Filtering()
    Dim LastRow As Long
    Set ws = ThisWorkbook.Sheets.Add
    ws.Name = "PERSONA3"
    Sheets("PERSONA3").Activate
    'Find the last row
    LastRow = Range("A1").CurrentRegion.Rows.Count
    'Select Table
    Range("A1:FB" & LastRow).Select
    'Filter Table
    Selection.AutoFilter Field:=AR, Criteria1:="Cigarette"
    'copy paste
    Selection.Copy
      Sheets("PERSONA3").Range("A1" & LastRow).PasteSpecial x1PasteValues
    'Turn off Auto Filter
    Selection.AutoFilter
End Sub
The expected results for this program should be that another spreadsheet is created with the filtered table inputted into the new spreadsheet
 
    