Consulting

Results 1 to 6 of 6

Thread: Pivot Table code that worked in 2003 not working with 2010

  1. #1
    VBAX Regular
    Joined
    Feb 2005
    Posts
    82
    Location

    Pivot Table code that worked in 2003 not working with 2010

    In 2003, this code executes
    [vba]ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
    Worksheets("Resource Summary").Range(Cells(1, 1), Cells(EndRow, EndCol))).CreatePivotTable _
    TableDestination:="'[Resource Calclulator.xls]Pivot Table'!R3C1", _
    TableName:="FTEPivotTable", _
    DefaultVersion:=xlPivotTableVersion10[/vba]
    It fails in 2010. I tried changing .Add to .Create, but I still get an error.
    Does someone know what has changed that is causing my failure?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't use PT's much. If you post a short example file, it is easier to help.

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    you can download an example file here:
    http://gallery.technet.microsoft.com...ample-c1be6ed3


    in the same file macro recorder produces:

    [VBA]
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Employees!R1C1:R19C8", Version:=xlPivotTableVersion14).CreatePivotTable _
    TableDestination:="[PivotTablesAndCharts.xlsm]Sheet1!R18C2", TableName:= _
    "PivotTable4", DefaultVersion:=xlPivotTableVersion14
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("DEPT")
    .Orientation = xlRowField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable4").PivotFields("LOCATION")
    .Orientation = xlColumnField
    .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
    "PivotTable4").PivotFields("SALARY"), "Sum of SALARY", xlSum
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You might want to check that you set the proper SourceData.

    [vba]msgbox Worksheets("Resource Summary").Range(Cells(1, 1), Cells(EndRow, EndCol)).Address[/vba]

    F8 stepping would show you the value of EndRow and EndCol.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Kenneth Hobs
    I don't use PT's much.
    What! I am speechless
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    This part:
    [vba]Worksheets("Resource Summary").Range(Cells(1, 1), Cells(EndRow, EndCol))[/vba]
    needs to be:
    [vba]Worksheets("Resource Summary").Range(Worksheets("Resource Summary").Cells(1, 1), Worksheets("Resource Summary").Cells(EndRow, EndCol))[/vba]
    or use a With...End With block.
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •