Macor Error 'AdvancedFilter method of range class failed'

subrahmanyam85

New Member
Joined
Aug 26, 2014
Messages
20
Macro Error 'AdvancedFilter method of range class failed'

I am using the below code to copy the unique column values from column A to column H in Pivot_Y(Pivot Table) by using UniqueList macro.This UniqueList calling from Worksheet_PivotTableUpdate in Pivot_Y.

Later I am moving these unique column values to some other sheet by using UniqueListAcrossSheets macro.

I am refreshing the Pivot table in Pivot_Y from another sheet filter by connecting to slicer of pivot table in Pivot_Y.

I am clearing contents of columns H,A before populating also.

I am getting the error "AdvancedFilter method of range class failed"

The below code is in Pivot_Y sheet.
'To run macro after pivot table refresh
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Call UniqueList
End Sub
'To get unique years
Private Sub UniqueList()
Dim LR As Long
'Clear contents in Column L
Range("H7", Range("H7").End(xlDown)).Clear
LR = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
Range("A7:A" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("H7"), Unique:=True
'Copy into other sheet
Call UniqueListAcrossSheets
End Sub
'Copy unique values from one sheet(Pivot_TPD299Y) to other sheets(GetYear_TPD299Y)
Sub UniqueListAcrossSheets()
Dim ULR As Long
Dim rSrc As Range
ULR = Worksheets("Pivot_TPD299Y").Cells(Rows.Count, "H").End(xlUp).Row
Set rSrc = Worksheets("Pivot_TPD299Y").Range("H7:H" & ULR)
Worksheets("GetYear_TPD299Y").Range("A1", Range("A1").End(xlDown)).Clear
rSrc.Copy Destination:=Worksheets("GetYear_TPD299Y").Range("A1")
End Sub
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,969
Messages
5,856,586
Members
431,822
Latest member
chaftun

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
Top