View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rowan Drummond[_3_] Rowan Drummond[_3_] is offline
external usenet poster
 
Posts: 414
Default pivot date field range

Maybe start with something like this:

Sub PvtDate()
Dim pvtTable As PivotTable
Dim pvtItem As PivotItem
Dim endDate As Date
Dim startDate As Date

startDate = Sheets("Sheet5").Range("A1").Value
endDate = Sheets("Sheet5").Range("B1").Value
Set pvtTable = Sheets("Sheet5").PivotTables("PivotTable1")

On Error Resume Next
pvtTable.PivotFields("Date").PivotItems(endDate).V isible = True
For Each pvtItem In pvtTable.PivotFields("Date").PivotItems
If pvtItem.Name < startDate Or pvtItem.Name endDate Then
pvtItem.Visible = False
Else
pvtItem.Visible = True
End If
Next pvtItem
On Error GoTo 0
End Sub

Hope this helps
Rowan

BorisS wrote:
I'd like for a person to be able to select from two cells on a sheet to enter
a date range. I'd like for my pivot table date page field to then use those
two end cap dates as the range for which to not hide items. Possible?

In other words, right now, I have to ask the user to go into the field
settings, deselect (for example) a month of dates and select another month,
every time they want to change the scope of the table. I'd like to make it
easier by forcing the table to just on its own take two cells and use a macro
to use those dates as the start and stop of its range.

If anyone has some code that can accomplish this, would mean a lot towards
user convenience on this thing.

Thx.