Results 1 to 2 of 2

Creating new Pivot table with dynamic sheet names/ranges

Threaded View

  1. #1
    Registered User
    Join Date
    08-08-2012
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2003
    Posts
    4

    Creating new Pivot table with dynamic sheet names/ranges

    I'm trying to create a pivot table on a new sheet with dynamic sheet names/ranges and I keep getting error "Invalid procedure call or argument" error. My code is below:


    Dim wb As Workbook
    Dim FinalRow As Long
    Dim FinalCol As Long
    
    
        WSD = ActiveSheet.Name
        Sheets.Add
        PS = ActiveSheet.Name
    
    FinalRow = Sheets(WSD).Cells(Application.Rows.Count, 1).End(xlUp).Row
    FinalCol = Sheets(WSD).Cells(1, Application.Columns.Count). _
        End(xlToLeft).Column
    ColName = Split(Cells(, FinalCol).Address, "$")(1)
    
    
        With ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
            WSD & "!$A$1:$" & ColName & "$" & FinalRow, Version:=xlPivotTableVersion14)
    
    'This next piece is setting off error: Invalid Procedure Call or Argument
    
              .CreatePivotTable _
                  TableDestination:=PS & "!$G$3", TableName:="PivotTable1", DefaultVersion _
                  :=xlPivotTableVersion14 
       End With
    Just for comparison sake, code when copied straight from the from macro:

     
     ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
            "Sheet1!R1C1:R412C21", Version:=xlPivotTableVersion14).CreatePivotTable _
            TableDestination:="Sheet19!R3C1", TableName:="PivotTable1", DefaultVersion _
            :=xlPivotTableVersion14
        Sheets("Sheet19").Select
        Cells(3, 1).Select
    All I've done is replace the static ranges with dynamic ones. Why isn't this working? Any help is appreciated!
    Last edited by KeriM; 05-07-2013 at 04:30 PM.

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