XcelThug
New Member
Hi Team,
Please help me out.
Please suggest any work around if the below code is completely wrong.
Note: The code which is there in the attached sheet is different from the below.
- I have a PivotTable(PivotTable1) in sheet(Pivot).
- I need to filter out the field(Date) in this pivot using Range("F3") and Range("F4")
Please help me out.
Please suggest any work around if the below code is completely wrong.
Note: The code which is there in the attached sheet is different from the below.
Code:
Sub Filter_ItemListInCode()
Dim pt As PivotTable
Dim Field As PivotField
Dim EDate As String
Dim SDate As String
Set pt = Worksheets("Pivot").PivotTables("PivotTable1")
Set Field = pt.PivotFields("Date")
SDate = Worksheets("Pivot").Range("F3").Value
EDate = Worksheets("Pivot").Range("F4").Value
With pt
Field.ClearAllFilters
Field.PivotFilters.Add Type:=xlDateBetween, Value1:=SDate, Value2:=EDate
pt.RefreshTable
End With
End Sub
Attachments
Last edited: