+ Reply to Thread
Results 1 to 1 of 1

to make a date invisible in pivot chart - macro

Hybrid View

  1. #1
    Registered User
    Join Date
    04-28-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2003
    Posts
    24

    Question to make a date invisible in pivot chart - macro

    Hi there

    I am building on from this here

    Attached is the file I am working off.

    I have the below macro that basically makes all the dates invisible(i.e. it removes the dates from the pivot chart). I am assuming all the dates are visible.

    Sub ShowAllItemsks1()
    Application.ScreenUpdating = False  '' this makes all the visible dates
                                        '' invisible except for one and comes with an error
    Dim ws As Worksheet
    Dim objPT As PivotTable
    Dim objPTField As PivotField
    Dim objPTItem As PivotItem
    Dim LastDate As Date
    
    
    LastDate = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp)
    MsgBox "Last Date is:" & LastDate & vbCrLf
     
    For Each ws In Worksheets
    ws.Visible = xlSheetVisible
        For Each objPT In ws.PivotTables
     MsgBox "Pivot table name: " & objPT.Name & vbCrLf & "Sheet name: " & ws.Name & vbCrLf & "test"
        With objPT
            
            '
            ' Run through all the row fields
            For Each objPTField In .RowFields
                    '
                    ' Get the hidden items and make them visible
                For Each objPTItem In objPTField.VisibleItems
                    objPTItem.Visible = False
                Next 'objPTItem
            Next 'objPTField
                    
                    
        End With
    Application.ScreenUpdating = True
     
        Next objPT
    Next ws
    End Sub
    But I get the following error, which is as I understand it to be, because this is the last date that is visible thereby it is not allowed to be made invisible.

    Run time error’1004’: Unable to set the Visible property of the PivotItem class
    Which points to this bit of code for debug

                    objPTItem.Visible = False
    Now what I want to do is make only one date disappear by changing the above code to

                    objPTItem(LastDate).Visible = False
    which gives the following

    Sub ShowAllItemsks3()
    Application.ScreenUpdating = False  '' this makes all the visible dates
                                        '' invisible except for one and comes with an error
    Dim ws As Worksheet
    Dim objPT As PivotTable
    Dim objPTField As PivotField
    Dim objPTItem As PivotItem
    Dim LastDate As Date
    
    
    LastDate = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp)
    MsgBox "Last Date is:" & LastDate & vbCrLf
     
    For Each ws In Worksheets
    ws.Visible = xlSheetVisible
        For Each objPT In ws.PivotTables
     MsgBox "Pivot table name: " & objPT.Name & vbCrLf & "Sheet name: " & ws.Name & vbCrLf & "test"
        With objPT
            
            '
            ' Run through all the row fields
            For Each objPTField In .RowFields
                    '
                    ' Get the hidden items and make them visible
                For Each objPTItem In objPTField.VisibleItems
                    objPTItem(LastDate).Visible = False
                Next 'objPTItem
            Next 'objPTField
                    
                    
        End With
    Application.ScreenUpdating = True
     
        Next objPT
    Next ws
    End Sub
    Which gives a compile error: Wrong number of arguments or invalid property assignment

    Can anyone help here please?

    Specifically, Can anyone suggest how I can make one date invisible as I am trying to do in Sub ShowAllItemsks3() above?

    Thanks
    Attached Files Attached Files
    Last edited by hattrick_123a; 10-12-2011 at 05:16 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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