+ Reply to Thread
Results 1 to 9 of 9

Dealing with Application Messages when running VBA - Error Handling

  1. #1
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Dealing with Application Messages when running VBA - Error Handling

    Hi,

    I have a drop down list that a user can select a period from (Q1,Q2,Q3,Q4). This list drives a named field called "Period". My code fires when the user makes a selection and changes the period on a string of pivots to reflect the selected period.

    It works fine as long as the pivots have data/a filter item for the period selected. If it doesn't then excel presents the message "No item of this name exists within Pivot Table report. Rename Q2 to Q4?"

    I've not done any error handling yet, so i googled how to use On Error and put something in the code but it doesn't work. Any idea on how i can get around this message and exit the sub with a message?

    AB8 and V20 are the cell references of the pivot item list for each pivot table.

    Thanks in advance,

    J

    Please Login or Register  to view this content.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Dealing with Application Messages when running VBA - Error Handling

    I reckon you would be better off changing the pivot table directly instead of overwriting a cell that it happens to be on. if it's a page field you are changing set its currentpage property to the value you want
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Dealing with Application Messages when running VBA - Error Handling

    OK, i'll have a look into that - i thought it seemed a bit of a fudge. Thanks!

    So would i then need to alter my code to check if the page item exists before i try and change it?

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Dealing with Application Messages when running VBA - Error Handling

    you can do that or simply add an error handler as before-you should get a 1004 error. presumably the pivots do not all run off the same data source?

  5. #5
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Dealing with Application Messages when running VBA - Error Handling

    No, they are indeed from separate data sources

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Dealing with Application Messages when running VBA - Error Handling

    shame-can't use slicers then

  7. #7
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Dealing with Application Messages when running VBA - Error Handling

    actually you can! Deborah (?) at the Contextures blog has some code that will change all pivot field items in every pivot on a worksheet when you use one slicer. I use it on this dashboard.

    However, for reasons i won't bother going into, for this circumstance it isn't appropriate.

    Thanks for pointing me in the direction of working with the pivot page items, found the following code (thank you again Deborah) which i have reworked for my needs.

    However, the underlying year value (i.e. the named range "year") - still changes, even if the values on the pivots do not - this puts them out of kilter. My next step is to figure out how to preserve the year until all the checks have been passed. But for now, thanks for the help.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Dealing with Application Messages when running VBA - Error Handling

    I meant using slicers instead of code not as well as ;-) (her name is Debra by the way)

  9. #9
    Forum Contributor
    Join Date
    04-13-2010
    Location
    England
    MS-Off Ver
    Office 2016 365
    Posts
    211

    Re: Dealing with Application Messages when running VBA - Error Handling

    Right! Well, i've got it all sorted now. Up and running so thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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