+ Reply to Thread
Results 1 to 22 of 22

Runtime error 438 in Pivot table macro

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Runtime error 438 in Pivot table macro

    Hello
    Could someone please advise why I get a runtime 438 error in the following:


    Sub PivotStatus()

    Dim pt As PivotTable

    Set pt = Worksheets("Status TEST").PivotTables("PivotTable1")
    pt.PivotFields("Organisation").ClearAllFilters
    pt.PivotFields("Organisation").CurrentPage = Range("Pivot_Org")

    End Sub
    This is excel 2003

    thanks
    Last edited by DavidBW; 01-13-2012 at 07:17 AM. Reason: inserting code tags

  2. #2
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    Know our resident experts are pretty busy or still on hols but would appreciate some insight
    thanks!

  3. #3
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Hi,
    There is no ClearAllFilters method in 2003. It was added (along with a lot of the other good pivot functionality) in 2007.
    Good luck.

  4. #4
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    OK thanks, thought that might the case

    Does anyone know any workarounds for this problem in 2003 ?

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Why do you need it in 2003 if you are setting the CurrentPage anyway?

  6. #6
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    Sorry, I don't understand the question.

    Just to outline what I'm trying to do:

    I have a pivot table ("PivotTable1") in the worksheet "Status TEST" which needs to change on the value selected in the "Organisation" filter. This value is found in the cell with range name "Pivot_Org" which is in a different worksheet.

    Thanks
    Last edited by DavidBW; 01-06-2012 at 08:07 AM.

  7. #7
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    What I am asking is why this will not suffice
    Please Login or Register  to view this content.
    since it will set the page field to whatever the specified value in Pivot_Org is.

  8. #8
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    Unfortunately I get a 1004 Runtime error with the following msg:

    "Unable to set the CurrentRange property of the PivotField class"

  9. #9
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    'Organisation' is a page field, rather than row or column field? What is the value in the named range?

  10. #10
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    The value is one of the choices of Organisations so for example in this case "Operations". In that cell (Pivot_Org) is a lookup formula which looks at the user input then pulls in a value equal to one the organisation choices. I thought of putting .Value after Range("Pivot_Org") but that didn't work either. However when I hover the cursor over the Range("Pivot_Org") it is showing the correct Organisation choice.
    Last edited by DavidBW; 01-06-2012 at 10:13 AM. Reason: additional text

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Could you post a small sample workbook, with the bare minimum of data for the pivot and any confidential information removed/censored?

  12. #12
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    Here you go, thanks for helping
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    correct file attached
    Attached Files Attached Files

  14. #14
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Organisation is not a page field, so you cannot use CurrentPage on it. You will have to set the pivotitem you want visible, then loop through the pivotitems, making all the others invisible. You need to do it in that order to ensure that you always have one item visible.

  15. #15
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    ok thanks, will give it a go and post solution (if it works!)

  16. #16
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Based upon your sample file
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    Thank you very much, this has worked perfectly!

    Could I please ask for one little tweak & that is the option to show all items?

    Thanks

  18. #18
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    This is untested but should be more or less right
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: Runtime error 438 in Pivot table macro

    Unfortunately get following Runtime 1004 error message when selecting "All" items, still works fine on individual choices:

    "Unable to set the visible property of the PivotItem class"

    Sub PivotStatus()

    Dim pt As PivotTable
    Dim pfld As PivotField
    Dim pitm As PivotItem
    Dim varFilter

    varFilter = Lcase$(Sheets("Data").Range("F13").Value)
    Set pt = Worksheets("Status TEST").PivotTables("PivotTable3")
    pt.ManualUpdate = True
    Set pfld = pt.PivotFields("Organisation")
    If varFilter = "all" then
    For Each pitm In pfld.PivotItems
    pitm.Visible = True <------------------ERROR highlighted here
    Next pitm
    Else
    pfld.PivotItems(varFilter).Visible = True
    For Each pitm In pfld.PivotItems
    pitm.Visible = (LCase(pitm.Name) = varFilter)
    Next pitm
    End If
    pt.ManualUpdate = False
    End Sub
    Thanks for helping
    Last edited by DavidBW; 01-10-2012 at 10:49 AM.

  20. #20
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Possibly old items in the data, or items that have no data - perhaps
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    SOLVED Re: Runtime error 438 in Pivot table macro

    Thank you that has worked & you managed to get your tag line in!

  22. #22
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Runtime error 438 in Pivot table macro

    Glad you noticed. ;-)

+ 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