+ Reply to Thread
Results 1 to 5 of 5

VBA Pivot Control not working Error 1004

  1. #1
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    VBA Pivot Control not working Error 1004

    I am having issue adding pivot columns dynamically using vba. I am using a changing variable PV_Col as string that is feeding the source name to be added to the table. The code im using is:
    Please Login or Register  to view this content.
    err1004glob.GIF

    When I change the code to "worksheets" I get the following error :
    Please Login or Register  to view this content.
    err1004pvt.GIF

    Not sure what im doing wrong here, any help would be appreciated.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: VBA Pivot Control not working Error 1004

    Check whether the value of PV_Col is exist in Pivot Table Filed.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    Re: VBA Pivot Control not working Error 1004

    I apologize for delay, just getting at circling back to this, PV_Col works as a variable place holder for the actual column, therefore when running the macro my intention is to have a userform which holds all possible column headers as available options. Any value selected matches the value pulled from using ex: "headername = ctl.Name". For whatever reason i am able to successfully clear all the selected values programatically, but it is the adding the specific pivot columns that does not work. any code generated by running the macro recorder does not seem to flow through when applying a scripted aproach.

  4. #4
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: VBA Pivot Control not working Error 1004

    Quote Originally Posted by penbeacho View Post
    Any value selected should match the value pulled from using...
    I fixed the above line for you. Unless you have checked and verified thats the case you cannot be sure it actually is. Add a debug.print line to output the value stored and/or put a watch on the variable and step through your code. As we only have 2 lines from your whole macro to help you by, we cant be certain something else isnt complicating things.

    Also the difference between Sheets and Worksheets is important to understand. Additionally you are implicitly using them both, does your macro work between workbooks or only in a single workbook? You may consider explicitly adding the parent workbook before it: IE: workbook.worksheet...

    Also what are the ,"FEE" and xlSum after that line? I cant find it documented anywhere.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  5. #5
    Registered User
    Join Date
    03-25-2015
    Location
    USA
    MS-Off Ver
    2010
    Posts
    34

    Re: VBA Pivot Control not working Error 1004

    The "should" matches every time I have tested, but due to errors I couldn't confirm 100%.

    "Fee" is the column header value.
    xlSum is the Pivot Table value Excel attaches to the sum function inside the pivot values.

    when it comes to sheets and worksheets there will be cross sheet moving within the same workbook, I have just been having a rough time trying to get by whatever means this part of the script to work. below is my current test bed code with several commented out approaches. The value of j is determined by a checkbox selection.

    Please Login or Register  to view this content.
    Last edited by penbeacho; 02-23-2018 at 12:40 AM.

+ 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. Error 1004 Can't move focus to the control because it is invisible....
    By ramtgig in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2017, 04:58 PM
  2. Dir error 1004. Previously working.
    By CptNoob in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2014, 09:45 AM
  3. Pivot table source not working run time error 1004
    By vba317 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-23-2014, 04:03 PM
  4. Pivot table source not working run time error 1004
    By vba317 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-22-2014, 05:15 PM
  5. VBA: Pivot Tables / Error 1004: Pivot Table Not Valid
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-22-2013, 03:54 PM
  6. Replies: 3
    Last Post: 03-29-2012, 01:58 PM
  7. [SOLVED] Copy Paste not working from Add-in - Error 1004
    By Trefor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2005, 04:45 AM

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