Just to bring closure to this thread, i've found the solution myself. Basically I make the pivot items refer to a cell in the worksheet, the cell holds a declared variable value.
Code is like this:-
Sub ShowAllVariance()
Dim pt As PivotTable
Dim i As Integer
Dim fdate As String
Dim fdate1 As String
Dim fdate3 As String
Dim fdate7 As String
Application.ScreenUpdating = False
Application.Calculation = xlManual
Set pt = Sheets("Mysheet").PivotTables("PivotTable1")
pt.PivotCache.Refresh
pt.PivotFields("Date").AutoSort xlDescending, "Date"
ClearItems 'macro to hide all pivot items
fdate = Sheets("Mysheet").Cells(10, 4).Value
fdate1 = Sheets("Mysheet").Cells(10, 4).Value - 1
fdate3 = Sheets("Mysheet").Cells(10, 4).Value - 3
fdate7 = Sheets("Mysheet").Cells(10, 4).Value - 7
pt.PivotFields("Date").PivotItems(fdate).Visible = True
pt.PivotFields("Date").PivotItems(fdate1).Visible = True
pt.PivotFields("Date").PivotItems(fdate3).Visible = True
pt.PivotFields("Date").PivotItems(fdate7).Visible = True
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
End Sub
Bookmarks