+ Reply to Thread
Results 1 to 3 of 3

Macro Pivot Table: Most elegant way to skip a "do not display" if element doesn't exist

Hybrid View

  1. #1
    Registered User
    Join Date
    08-15-2013
    Location
    London
    MS-Off Ver
    Multiple versions
    Posts
    27

    Question Macro Pivot Table: Most elegant way to skip a "do not display" if element doesn't exist

    I'm writing a macro to Pivot a ream of data into a tabulated form for easier reading.

    Occasionally, the data subset will contain a "blank" entry that - while not a problem - I would rather not display in the Table (for clarity).

    The following removes it:
        With ActiveSheet.PivotTables("SortedTable").PivotFields("Message")
            .PivotItems("(blank)").Visible = False
        End With
    But if the raw data happens to NOT contain any blanks, it fails with the message:

    "Run-time error '1004':
    Unable to get the PivotItems property of the PivotField class


    Could someone advise the most elegant way of programming - "If there are no BLANK items then don't bother trying this"?

    Thanks in advance.

    Steve

  2. #2
    Registered User
    Join Date
    08-15-2013
    Location
    London
    MS-Off Ver
    Multiple versions
    Posts
    27

    Re: Macro Pivot Table: Most elegant way to skip a "do not display" if element doesn't exis

    By the way - although elegance would be all well and good, any suggestions as to how to achieve it at all would be appreciated, as I just keep drawing blanks.

    Steve

  3. #3
    Registered User
    Join Date
    08-15-2013
    Location
    London
    MS-Off Ver
    Multiple versions
    Posts
    27

    Re: Macro Pivot Table: Most elegant way to skip a "do not display" if element doesn't exis

    Hurrah! I worked a way out myself, and it was more obvious that I expected.

    So I will write my solution here in case anyone ever goes looking, but am still interested if there are better ways, or pitfalls to this one.

    All I did was put an "On Error Resume Next" before the With command, and it stopped the runtime error.
      ' Set all the BLANK messages to not show
        On Error Resume Next    ' stops a runtime error if there are no "blank" lines to hide
        With ActiveSheet.PivotTables("SortedTable").PivotFields("Message")
            .PivotItems("(blank)").Visible = False
        End With
    That's good enough for my situation.

    Steve

+ 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: 2
    Last Post: 06-06-2013, 12:45 PM
  2. Replies: 0
    Last Post: 03-10-2013, 04:19 PM
  3. How make a pivot table display values greater than "X"
    By austinrob in forum Excel General
    Replies: 3
    Last Post: 04-03-2012, 12:46 PM
  4. If a Value Doesn't Exist in a Table, Return ""
    By Ocean Zhang in forum Excel General
    Replies: 7
    Last Post: 06-23-2011, 04:13 PM
  5. [SOLVED] "Show Field List" in Pivot Table Toolbar doesn't work
    By Flyer27 in forum Excel General
    Replies: 0
    Last Post: 04-11-2006, 07:10 PM

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