+ Reply to Thread
Results 1 to 3 of 3

Error when running a macro to create a pivot table in Excel 2010

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    Bradford
    MS-Off Ver
    Excel 2010
    Posts
    2

    Error when running a macro to create a pivot table in Excel 2010

    Hi,

    I've written some vba code to create a pivot table (the input range may vary and has been accounted for)


    ' This creates Dynamic data range named "PvtData"

    Sheets("data import month").Select
    ActiveWorkbook.Names.Add Name:="PvtData", RefersToR1C1:= _
    "=OFFSET('Data Import Month'!R1C1,0,0,COUNTA('Data Import Month'!C1),COUNTA('Data Import Month'!R1))"


    Create the pivot table

    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "PvtData", Version:=xlPivotTableVersion14). _
    CreatePivotTable TableDestination:="Data Import Month!R3C4", TableName:= _
    "PivotTable1", DefaultVersion:=xlPivotTableVersion14



    Cells(3, 4).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Post_sector")
    .Orientation = xlRowField
    .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("Policy_Cnt"), "Sum of Policy_Cnt", xlSum
    End Sub


    The highlighted red code is where i come across the error Run-time error 5: invalid procedure, call or argument

    Any suggestions please

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

    Re: Error when running a macro to create a pivot table in Excel 2010

    I reckon you're missing some quotes in the tabledestination because there are spaces in the sheet name
    Please Login or Register  to view this content.
    Josie

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

  3. #3
    Registered User
    Join Date
    07-11-2012
    Location
    Bradford
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Error when running a macro to create a pivot table in Excel 2010

    Thanks that seems to have worked

+ 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