View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Spacedman Spacedman is offline
external usenet poster
 
Posts: 1
Default Excel2007 VBA - dates in Pivot Tables not read in correct format

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("Da te")
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