Consulting

Results 1 to 2 of 2

Thread: Unable to set the visible property of the pivot item class

  1. #1
    VBAX Regular
    Joined
    Mar 2015
    Posts
    16
    Location

    Unhappy Unable to set the visible property of the pivot item class

    Hi

    I have the following code, it keeps coming up with error 1004 'unable to set the visible property of the pivot item class' Any ideas?

    The code exports and filters data on the pivot table by principle investigator name to a new sheet.

    Sub CopyPivDataPI()

    Dim PT As PivotTable
    Dim PI As PivotItem
    Dim PI2 As PivotItem

    '1)Worksheet name where PIVOT Table is located
    MyWs = "Monthly Summary"
    '2)PIVOT table name/number, note by default the first one created is PivotTable1
    MyPIV = "PivotTable1"
    '3)Field Name that you want to use for breaking out by, i.e. the filter name
    MyField = "Principle investigator"

    Set PT = Worksheets(MyWs).PivotTables(MyPIV)
    With PT

    For Each PI In Worksheets(MyWs).PivotTables(MyPIV).PivotFields(MyField).PivotItems
    PI.Visible = True

    For Each PI2 In Worksheets(MyWs).PivotTables(MyPIV).PivotFields(MyField).PivotItems
    If Not PI2.Name = PI.Name Then PI2.Visible = False
    Next PI2
    Set NewWs = Worksheets.Add
    NewWs.Name = PI & " " & Format(Date, "mmm-yy")




    'You will need to amend the range below to copy the correct amount of data for your file
    Worksheets(MyWs).Range("A1:Z345").Copy

    'This pastes into cell A1 of the new sheet
    NewWs.Range("A1").Select
    ActiveSheet.Paste
    Next PI



    Application.ScreenUpdating = False
    Dim wkSt As String
    Dim wkBk As Worksheet
    wkSt = ActiveSheet.Name
    For Each wkBk In ActiveWorkbook.Worksheets
    On Error Resume Next
    wkBk.Activate
    Cells.EntireColumn.AutoFit
    Next wkBk
    Sheets(wkSt).Select
    Application.ScreenUpdating = True
    End With
    End Sub
    Last edited by Emily2; 07-03-2015 at 04:07 AM.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    as an experienced vbax member you should have pasted your code in between code tags.

    [ CODE ]Paste your code here and remove spaces before and after brackets[ /CODE ]

    can you post your workbook for a better understanding of the sheet and pivot table structure?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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