Excel2007 VBA - dates in Pivot Tables not read in correct format

S

Spacedman

If I create a PivotTable with a field called DATE containing dates formatting
as dd/mm/yy, I then use this macro to remove Saturdays and Sundays from the
PivotTable. Except it reads the dates a mm/dd/yy until they are 'out of
scope' and then they are read as dd/mm/yy. Why?

Sub HideWeekendsFromPivotTable()
Dim pivotName As String
Dim pivotDate As Date
Dim z, pivotCount As Long

pivotName = ActiveSheet.PivotTables(1).Name

With ActiveSheet.PivotTables(pivotName).PivotFields("Date")
pivotCount = .PivotItems.Count

For z = 1 To pivotCount

If Weekday(.PivotItems(z).Name) = 1 Or
Weekday(.PivotItems(z).Name) = 7 Then _
.PivotItems(z).Visible = False

Next z
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top