Question about using a date variable in a Pivot table
I'm trying to tweak a piece of my code to allow me to use a date as a variable in selecting information in my pivot table. Here's my code:
Sub RS_IBOB_Open_Select()
'
' RS_IBOB_Open_Select Macro
'
'
SelectDate = Format(Date - 1, "YYYYMMDD")
WShtDate = Format(Date - 1, "mm.dd.yy")
BOCM = Format(DateSerial(Year(Date), Month(Date), 1), "mm.yyyy") 'Begin of Curr Month
Application.DisplayAlerts = False
Workbooks.Open Filename:= _
"http://mminet/sites/fcmgt/Michael%20Cagan/RS%20Day-Week-Month/Updated%20Daily/Right%20Start%20Inbound-Outbound/RS%20Inbound-Outbound%20Tracking%20" & BOCM & ".xlsx"
Sheets(WShtDate).Select
Workbooks.Open Filename:="H:\BI Reports\RS IB - OB.xlsx"
ActiveSheet.PivotTables("PivotTable1").PivotCache. Refresh
ActiveSheet.PivotTables("PivotTable1").PivotFields ("[Date].[Day].[Day]"). _
VisibleItemsList = Array("[Date].[Day].&[20110105]")
End Sub
The very last row is the one I am interested in making a variable:
VisibleItemsList = Array("[Date].[Day].&[20110105]")
Can I make the 20110105 a variable? I've tried to play around with the code to do something like
SelectData = format(Date - 1, "yyyymmdd")
VisibleItemsList = Array("[Date].[Day].&[SelectData]")
That didn't work so I tried
VisibleItemsList = Array("[Date].[Day].&[" & SelectData &"]")
Any thoughts?