Results 1 to 5 of 5

Pivot Table Not Selecting Max Week

Threaded View

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    84

    Pivot Table Not Selecting Max Week

    I'm trying to write some code where it will select the max pivot item in "Workweek". However, I can't get it to quite work right. Thanks for your help.

    Sub DW_Records_Setup()
    '3 DW_Records_Setup
    Dim wk4 As Worksheet
    Set wk4 = ThisWorkbook.Worksheets("Pivot_Example")
    
    Dim piItem As PivotItem
    Dim lngMaxValue As Double
    Set piItem = Nothing
     
     
    'code below is for GetBook variable with all connections, rewrite later to a public variable
    ThisWorkbook.ActiveSheet.PivotTables("PivotTable1").ClearTable
    
    With wk4.PivotTables("PivotTable1")
        .InGridDropZones = True
        .RowAxisLayout xlTabularRow
    End With
    
    With wk4.PivotTables("PivotTable1").PivotFields("Workweek")
        .Orientation = xlPageField
        .Position = 1
    End With
    
    wk4.PivotTables("PivotTable1").AddDataField wk4.PivotTables( _
        "PivotTable1").PivotFields("Sales"), "Sum of Sales", _
        xlSum
    
    wk4.PivotTables("PivotTable1").PivotFields("Workweek").ShowAllItems = False
    
    'added code below this line for auto update
    For Each piItem In wk4.PivotTables("PivotTable1").PivotFields("Workweek").PivotItems
      If piItem.Value > lngMaxValue Then lngMaxValue = piItem.Value
    
    With wk4.PivotTables("PivotTable1").PivotFields("Workweek") 'added with statement in the loop
        .PivotItems(lngMaxValue).Visible = True
        .PivotItems(piItem.Value).Visible = False
        .EnableMultiplePageItems = True
    End With
    
    pvtcount = pvtcount + 1
    Next piItem
    
    Set piItem = Nothing
    
    x = 1
    
    With wk4.PivotTables("PivotTable1").PivotFields("Workweek") 'added with
        For x = 1 To pvtcount
        If .PivotItems(x).Value = lngMaxValue Then
        .PivotItems(x).Visible = True
        End If
        Next
        .PivotItems("14").Visible = False
        .EnableMultiplePageItems = True
    End With
    
    
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I want to add a 16 week rolling AVG in a pivot table.
    By krisarmstrong in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 10-21-2014, 02:33 PM
  2. Pivot Table that groups by day of week.
    By travkliewer in forum Excel General
    Replies: 2
    Last Post: 07-03-2014, 07:07 PM
  3. Cache of Pivot table is not selecting the table values
    By Menaka in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-06-2013, 07:39 AM
  4. Replies: 0
    Last Post: 03-22-2009, 07:17 PM
  5. [SOLVED] Pivot table displayed by day of the week
    By Dan in forum Excel General
    Replies: 3
    Last Post: 02-20-2005, 03:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1