+ Reply to Thread
Results 1 to 5 of 5

Pivot Table pagefield returns wrong data when changed with vba

  1. #1
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Pivot Table pagefield returns wrong data when changed with vba

    Hello All,

    Okay, have a combobox populated with salespeople
    you select one and click a "lookup" button. This changes the page fields of multiple pivottables to that salesperson.

    here is the problem. On occasion, the data that is returned actually belongs to a different salesperson. Like if I specify Fred, the page field will be changed to Fred, but when I drill down and have a sheetx with sourcedate, the saleperson will turn out to be Susan.

    wtf excel? I thought we had a deal!

    Any idea what might be causing it?

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pivot Table pagefield returns wrong data when changed with vba

    It'd be easier to figure out if you'd post a sample workbook, or at least your code.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Re: Pivot Table pagefield returns wrong data when changed with vba

    Here is the code, not sure I can replicate the behaviour in a sample notebook


    Please Login or Register  to view this content.
    so what my issue is, is that sometimes, I'll put "John Smith" in the combobox (Sheet8.CL_SalesPersonLookup.Value) and the pivottable page field will say "John Smith" but the data will reflect the sales of "Jennifer Garner". And when I drill down to the raw data (with it creating a new sheet) the salesperson in the column will be "Jennifer Garner"

    it happens sporatically. I first noticed it always happened with a person named with the following syntax: firstname * lastname. Althought I don't think the asterisk does anything to muck up my results. It happens often enough that I don't trust it anymore

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pivot Table pagefield returns wrong data when changed with vba

    A couple things:
    1) This code a very difficutl to read for a couple of reasons. You should always declare all your variables at the beginning of the procedure, not throughout the code as you need them. Also, don't name a variable as the variable type (Ex: Dim Worksheet as Worksheet = bad).

    2) I don't believe using the error catcher is the best way to find out if a valid selection was made. Maybe you could skip that altogether by using a listbox to capture all the available salespersons?

    Other than that, I can't find anything that would cause the problem you stated above. Anyone else want to take a crack at it?

  5. #5
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Re: Pivot Table pagefield returns wrong data when changed with vba

    Thank you,

    the error catcher is because some of the pivottables reference a query that would have all the salespeople in it (distribution of quota across provinces) and other tables reference sales (the error checker is for those items dependent on sales)

+ 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