meru
meru

Reputation: 47

VBA Excel: Filter a column

I am trying to filter a column as I had many times earlier. But getting error as below:

1004: "Autofilter method of Range class failed"

Set wkb1 = Workbooks.Open("D:\Meru\Work\Trace Reports\Automation\Macro Codes\" & CFname & "\Daily Pivots -" & CfolderN & ".xls")

With wkb1.Worksheets("winloss")
    LastRow5 = .Cells(.Rows.Count, "A").End(xlUp).Row
    'MsgBox LastRow
    Set My_Range = .Range("V1:V" & LastRow5)
    'MsgBox My_Range
    My_Range.AutoFilter Field:=22, Criteria1:="Won", Operator:=xlFilterValues
  '   LastRow = .Cells(.Rows.Count, "G").End(xlUp).Row

    .UsedRange.Copy
End With

With wkb1.Worksheets("Trial")
    .Range(.Cells(1, "A"), .Cells(LastRow5, "A")).PasteSpecial xlPasteValues
End With

Upvotes: 1

Views: 2500

Answers (1)

Subodh Tiwari sktneer
Subodh Tiwari sktneer

Reputation: 9976

Since the range to be filtered contains only one column, it should be like this...

My_Range.AutoFilter Field:=1, Criteria1:="Won", Operator:=xlFilterValues

Upvotes: 3

Related Questions