Hi there
Appreciate any help as I am building on from this post here
I have the below bit of code that I want to go through my pivot chart and make the last 7 days of data visible.
I am having trouble with the Do loop. When I comment out the Do loop it runs okay. When I add the Do loop it dosen’t do the Do loop.
Can anyone suggest anything?
Here I am assuming that the date 07/09/2011 is the only date visible in the pivot chart. So when I run this macro the 11/09/2011 will also be visible in the pivot chart.
When I get the do loop working I hope to have the 11th to the 18th visible( it is still in early stages so a bit of fine tuning needed also)
Sub ShowAllItems7Days_test()
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim objPT As PivotTable
Dim objPTField As PivotField
Dim objPTItem As PivotItem
Dim LastDate As Date
Dim LastDate7 As Date
LastDate = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp)
LastDate7 = LastDate - 7
MsgBox "LastDate is:" & LastDate & vbCrLf & "LastDate7 is:" & LastDate7 & vbCrLf
For Each ws In Worksheets
ws.Visible = xlSheetVisible
For Each objPT In ws.PivotTables
MsgBox "Pivot table name: " & objPT.Name & vbCrLf & "Sheet name: " & ws.Name & vbCrLf & "test"
'Do Until LastDate7 <= LastDate
MsgBox "inside Do"
With objPT.PivotFields("date")
.PivotItems(LastDate7).Visible = True
End With
LastDate7 = LastDate7 + 1
'LastDate = LastDate - 1
'Loop
MsgBox "LastDate is:" & LastDate & vbCrLf & "LastDate7 is:" & LastDate7 & vbCrLf
Application.ScreenUpdating = True
Next objPT
Next ws
End Sub
Bookmarks