Results 1 to 10 of 10
  1. #1
    Mithril28 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    21

    Worksheet has multiple pivot tables -Unable to get the PivotFields property of the PivotTable class.

    I know there are 18 million posts about this error, but I have not found anything that works with multiple pivot tables


    I have a worksheet with multiple pivot tables named PivotTable1, PivotTable 2 etc.
    Each has a date filter, the field for every pivot table is named date, each has the same set of dates
    Every week this spreadsheet is updated with another set of data for the previous week, and the customer needs the date filter to have the latest three dates selected.
    So after the spreadsheet is refreshed I want the macro to deselect the 4th oldest date, and select the newest date
    But! Since it has multiple pivot tables, it fails on the bolded code below.
    Any suggestions welcome. My brain hurts!

    It is not my spreadsheet so I can't modify anything about it.

    Code:
    Sub SetDates()
        Dim St As Worksheet
        Dim NewSt As Worksheet
        Dim pt As PivotTable
        Application.ScreenUpdating = False
        ThisWorkbook.RefreshAll
        With NewSt
         With ActiveSheet.PivotTables("PivotTable1").PivotFields("Date")
            For Each St In ActiveWorkbook.Worksheets
                For Each pt In St.PivotTables
        pt.PivotFields("Date").PivotItems("8/08/2016").Visible = False
        pt.PivotFields("Date").PivotItems("8/29/2016").Visible = True
                Next
            Next
            End With
            End With
        Application.ScreenUpdating = True
    End Sub

  2. #2
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,792
    Colored text might work between code tags but bolding doesn't. Can't tell which line is generating the error.
    Try color or 'comment on the line.
    Each has a date filter, the field for every pivot table is named date, each has the same set of dates
    Every week this spreadsheet is updated with another set of data for the previous week, and the customer needs the date filter to have the latest three dates selected.
    I don't get where all these dates are coming from. If each pt has the same dates, where are the "latest three dates" coming from. Selected from where, the pt? The spreadsheet that the pt is on?
    EDIT: after re-reading, this isn't Automation from Access as I first thought. It looks like it's purely Excel, but you are posting vba code in an Access forum in the Macros section?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I think I see
    With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Date")

    But, I don't see as well as I used to. Because of this, I have crazy settings on my monitors and graphics.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,792
    You see bold font in that code? I don't. It's all the same, like Courier, perhaps, with no formatting.

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Since it has multiple pivot tables, it fails on the bolded code below.
    the bolded line is

    With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Date")


    but my question is - what does 'fail' mean? What error do you get?

    Also be aware that Date is a reserved word (in vba it means Today) and using reserved words can generate unexpected and misleading errors

  6. #6
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,792
    I wondered about "Date" as well, but figured it might be OK since it was in quotes. I suspect the main issue is that the worksheets and pivot table have been declared but not SET to anything. Then again, it may be that the ActiveSheet has no pivot table when this starts.

    But to me, it all looks weird, like the OP is trying to work with a worksheet nested on a worksheet pivot table (impossible?), and is then trying to loop through a set of worksheets from there. I thought the idea was to loop through pivot tables on worksheets, but if not, it still seems problematic to attempt to access a worksheet on a worksheet.

    Code:
    With NewSt <-- this has not been set
         With ActiveSheet.PivotTables("PivotTable1").PivotFields("Date")
              For Each St In ActiveWorkbook.Worksheets<--St is a worksheet object (not SET) but is not a member of the ActiveSheet anyway.
    And what looks like an attempt to affect two different pivot tables
    Code:
    pt.PivotFields("Date").PivotItems("8/08/2016").Visible = False
    pt.PivotFields("Date").PivotItems("8/29/2016").Visible = True
    is really the same one since this is being done in a loop
    For Each pt In St.PivotTables

    Next

    BTW, I'm still curious as to why I don't see bolded code. I'm using Firefox 48.0.2
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Mithril28 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2015
    Posts
    21
    Oh My GOSH!!! I don't know what to say except to apologize. My question is about an excel macro and this is indeed an Access forum. Sigh. I'll post to an excel forum.

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Micron View Post
    ...
    BTW, I'm still curious as to why I don't see bolded code. I'm using Firefox 48.0.2
    I am using I.E. What happens if you copy the text and paste it somewhere else? Does it retain the font style? I would guess it is simply not readily apparent. I can't imagine the browser not wanting to render the HTML correctly.

  9. #9
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,792
    Courier 10 when pasted into Word - no formatting. Must be my monitor, because this is what it looks like in FF
    Click image for larger version. 

Name:	FFforumFont.jpg 
Views:	6 
Size:	9.1 KB 
ID:	25676

    and in IE 11
    Click image for larger version. 

Name:	IEforumFont.jpg 
Views:	6 
Size:	9.0 KB 
ID:	25677
    There is a very slight bolding with IE, but if I wasn't told it was bold, I'd never see it. Probably doesn't show up in a picture.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Yup, that's the font how I saw/see it (the IE version you posted). The only difference for me is the edges of each character are crisp, to the point I can tell it is larger and darker.
    .
    Click image for larger version. 

Name:	courier_font.png 
Views:	5 
Size:	11.9 KB 
ID:	25678

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple Pivot Tables in 1 Form/Report
    By makybe05 in forum Forms
    Replies: 3
    Last Post: 11-18-2014, 03:24 AM
  2. Sort Columns in an excel worksheet and Pivot table
    By Jhail83 in forum Programming
    Replies: 3
    Last Post: 09-04-2013, 09:07 AM
  3. Replies: 1
    Last Post: 08-01-2012, 03:56 PM
  4. Replies: 1
    Last Post: 12-18-2011, 01:28 AM
  5. Replies: 2
    Last Post: 11-05-2010, 04:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums