+ Reply to Thread
Results 1 to 9 of 9

Error on Pivot Table VBA

  1. #1
    Registered User
    Join Date
    05-31-2010
    Location
    Manila
    MS-Off Ver
    Excel 2007
    Posts
    88

    Error on Pivot Table VBA

    Hi, I got a sample VBA code form this forum, this is to insert Pivot Table, and I tried modifying it, but it just gave me an error.

    Please Login or Register  to view this content.
    This line is giving me the error
    Please Login or Register  to view this content.
    Thanks!!
    Attached Files Attached Files

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,003

    Re: Error on Pivot Table VBA

    Your data starts in row 2 of your data sheet, not row 1, so you need to adjust two lines:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    05-31-2010
    Location
    Manila
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Error on Pivot Table VBA

    Thanks romperstomper!

    But another thing

    I was trying to modify this line:

    .Orientation = xlDataField

    instead of xlDatafield I'm trying to change it to xlcolumnfield since I want to be "Pieces Ordered" to be a column header instead of being in a row. But it gives me an error on this line:
    .Function = xlSum

    Thanks for your time!

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,003

    Re: Error on Pivot Table VBA

    If it's not a data field, then you can't sum it - you just get one column for each value. Are you trying to align the datafields in columns rather than rows?

  5. #5
    Registered User
    Join Date
    05-31-2010
    Location
    Manila
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Error on Pivot Table VBA

    Yes, I need to align it in Columns. Please see snapshot attached.

    Thanks!
    Attached Images Attached Images
    Last edited by geng; 06-02-2010 at 02:35 AM. Reason: for clearer view

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,003

    Re: Error on Pivot Table VBA

    You basically need to add:
    Please Login or Register  to view this content.
    after adding the data fields.

  7. #7
    Registered User
    Join Date
    05-31-2010
    Location
    Manila
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Error on Pivot Table VBA

    Where will I add it?

    In this?
    Please Login or Register  to view this content.
    I tried doing it like this:
    Please Login or Register  to view this content.
    And like this:
    Please Login or Register  to view this content.
    But still gives me error and highlight the xlcolumnfield line

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,003

    Re: Error on Pivot Table VBA

    Quote Originally Posted by romperstomper View Post
    after adding the data fields.
    (emphasis added)

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-31-2010
    Location
    Manila
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Error on Pivot Table VBA

    Thanks romperstomper, I'll try the code then I'll let you know!

    thanks!

+ 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