+ Reply to Thread
Results 1 to 1 of 1

VBA Max Workweek

Hybrid View

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

    Unhappy VBA Max Workweek

    My question is why does my code crap out on finding the max and leaves 18, 19 and 20 selected in the attached PNG for Workweek"? Does Excel have max or min of Pivot Items it can select?

    I tried using the macro I have on a fresh copy of Excel to get rid of any behind the scene errors.

    This is the code I use albeit very shorten.

    Thanks for your help.

    Sub Search_Pivot_Setup()
    '1
    ' Search_Pivot_Setup Macro
    
    Application.DisplayAlerts = False
    
    'add worksheets
    Dim wk1 As Worksheet
    Set wk1 = ThisWorkbook.Worksheets("Records")
    Dim piItem As PivotItem
    Dim lngMaxValue As Double
    Set piItem = Nothing
    
    
    ThisWorkbook.ActiveSheet.PivotTables("PivotTable1").ClearTable
    
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    'Turned off calculations and screen updating
    
    With wk1.PivotTables("PivotTable1")
        .InGridDropZones = True
        .RowAxisLayout xlTabularRow
    End With
    With wk1.PivotTables("PivotTable1").PivotFields("Workweek")
    .Orientation = xlPageField
    .Position = 1
    .PivotItems("2").Visible = False
    .EnableMultiplePageItems = True
    End With
    'added code
    For Each piItem In wk1.PivotTables("PivotTable1").PivotFields("Workweek").PivotItems
    On Error Resume Next
      If piItem.Value > lngMaxValue Then lngMaxValue = piItem.Value
    With wk1.PivotTables("PivotTable1").PivotFields("Workweek") 'added with statement in the loop
        .Orientation = xlPageField
        .Position = 1
        .PivotItems(lngMaxValue).Visible = False
        .EnableMultiplePageItems = True
    End With
    Next piItem
    
    With wk1.PivotTables("PivotTable1").PivotFields("Workweek") 'added with
        .Orientation = xlPageField
        .Position = 1
        .PivotItems(lngMaxValue).Visible = True
        .EnableMultiplePageItems = True
    End With
    With wk1.PivotTables("PivotTable1").PivotFields("Workweek")
    .Orientation = xlPageField
    .Position = 1
    .EnableMultiplePageItems = True
    End With
    End Sub
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 07-13-2014, 09:37 AM
  2. Replies: 5
    Last Post: 01-08-2013, 11:38 AM
  3. Save file with ISO correct Workweek
    By matt4003 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-12-2010, 04:38 PM
  4. Workday function - 6 day workweek
    By lblake25 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-20-2006, 04:18 PM
  5. [SOLVED] 4 Day Workweek
    By EasleyK in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-29-2005, 02:07 AM

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