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
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: