+ Reply to Thread
Results 1 to 9 of 9

Invalid argument or procedure Pivot chart vba

  1. #1
    Registered User
    Join Date
    03-31-2010
    Location
    Utah, America
    MS-Off Ver
    Excel 2007
    Posts
    18

    Invalid argument or procedure Pivot chart vba

    I didn't think this was going to be hard, but, i'm trying to set up a pivot chart using VBA, so I recorded a Macro, but now even when I try to use that same macro I get the "Run-time error '5':
    Invalid procedure call or argument

    I just think it's weird that I get that after recording a macro and not changing anything, but maybe someone could help me with this. Here is what the recording comes up with:

    Sub Macro7()

    ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, SourceData:= _
    "ICS-GSD-Account Management!R2C1:R1106C8", Version:=xlPivotTableVersion10). _CreatePivotTable TableDestination:="ICS-GSD-Account Management!R2C9", _
    TableName:="PivotTable10", DefaultVersion:=xlPivotTableVersion10
    Sheets("ICS-GSD-Account Management").Select
    Cells(2, 9).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range( _
    "'ICS-GSD-Account Management'!$I$2:$O$15")
    ActiveChart.ChartType = xlColumnClustered
    End Sub



    When I run the macro, the error comes up for the first part:

    ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, SourceData:= _
    "ICS-GSD-Account Management!R2C1:R1106C8", Version:=xlPivotTableVersion10). _
    CreatePivotTable TableDestination:="ICS-GSD-Account Management!R2C9", _
    TableName:="PivotTable10", DefaultVersion:=xlPivotTableVersion10

    But I can't really tell what's wrong in there.

    Eventually i want to adapt this so that it runs through each of the sheets in my workbook, but I can't even get this initial code to work. Any hlep that you have would be great

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Invalid argument or procedure Pivot chart vba

    Can you put code tags around your code, please? It makes it easier to read, and we can't assist you until you do.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    03-31-2010
    Location
    Utah, America
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Invalid argument or procedure Pivot chart vba

    sorry about that, let me see if this works, this is my first time posting on one of these thigns

    Please Login or Register  to view this content.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Invalid argument or procedure Pivot chart vba

    Thanks.
    Did you delete the original pivot table you created (In case it's trying to overwrite it)?

  5. #5
    Registered User
    Join Date
    03-31-2010
    Location
    Utah, America
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Invalid argument or procedure Pivot chart vba

    Yeah, i got it deleted, which is why i thought it was odd that it wouldn't run, since i had just recorded it

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Invalid argument or procedure Pivot chart vba

    Let's break the code down a bit so we can try and narrow down the exact error. Try this version:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-31-2010
    Location
    Utah, America
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Invalid argument or procedure Pivot chart vba

    ok, i tried that, and went into a step through, this time it gave me the error at the line:


    Please Login or Register  to view this content.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,343

    Re: Invalid argument or procedure Pivot chart vba

    OK, change that to:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-31-2010
    Location
    Utah, America
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Invalid argument or procedure Pivot chart vba

    That got it! thanks so much

  10. #10
    Registered User
    Join Date
    07-28-2014
    Location
    Kingston, Ontario
    MS-Off Ver
    2010
    Posts
    0

    Re: Invalid argument or procedure Pivot chart vba

    Good Morning Romperstomper or in your case evening. I have a similar issue with the Macro. I am trying to basically trying to build a print button that will create a pivot table before it prints for our employee travel expense forms.

    I have tried to incorporate your solution to this issue from a previous thread but I am getting hung up. This is my original macro

    Range("A11").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Pivot", Version:=xlPivotTableVersion14).CreatePivotTable TableDestination _
    :="Travel Expense!R47C1", TableName:="PivotTable11", DefaultVersion:= _
    xlPivotTableVersion14

    Sheets("Travel Expense").Select
    Cells(47, 1).Select

    And this is what I have tried to incorporate:
    Dim pc As PivotCache, pt As PivotTable
    Dim cht As Chart
    Set pc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Pivot", Version:=xlPivotTableVersion14)
    Set pt = pc.CreatePivotTable(TableDestination:=Sheets().Cells(47, 1), _
    TableName:="", DefaultVersion:=xlPivotTableVersion14)

    Thanks in advance for any help you can give.

  11. #11
    Registered User
    Join Date
    07-28-2014
    Location
    Kingston, Ontario
    MS-Off Ver
    2010
    Posts
    0

    Re: Invalid argument or procedure Pivot chart vba

    Good Morning Romperstomper or in your case evening. I have a similar issue with the Macro. I am trying to basically trying to build a print button that will create a pivot table before it prints for our employee travel expense forms.

    I have tried to incorporate your solution to this issue from a previous thread but I am getting hung up. This is my original macro

    Range("A11").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Pivot", Version:=xlPivotTableVersion14).CreatePivotTable TableDestination _
    :="Travel Expense!R47C1", TableName:="PivotTable11", DefaultVersion:= _
    xlPivotTableVersion14

    Sheets("Travel Expense").Select
    Cells(47, 1).Select

    And this is what I have tried to incorporate:
    Dim pc As PivotCache, pt As PivotTable
    Dim cht As Chart
    Set pc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Pivot", Version:=xlPivotTableVersion14)
    Set pt = pc.CreatePivotTable(TableDestination:=Sheets().Cells(47, 1), _
    TableName:="", DefaultVersion:=xlPivotTableVersion14)

    Thanks in advance for any help you can give.

+ 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