Results 1 to 4 of 4

Cannot create a pivot table reference.

Threaded View

GoPack1 Cannot create a pivot table... 06-21-2009, 12:59 PM
Leith Ross Re: Bug I can't figure out 06-21-2009, 01:06 PM
GoPack1 Re: Bug I can't figure out 06-21-2009, 01:37 PM
Leith Ross Re: Cannot create a pivot... 06-21-2009, 01:47 PM
  1. #1
    Registered User
    Join Date
    06-21-2009
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Cannot create a pivot table reference.

    I have the following code to create a pivot table from a data set. I get a Reference is Not Valid at the red line below. I know the fix must be simple, but I have hit a blank on the fix.

    Thanks in advance.


     Dim WSD As Worksheet
        Dim WSData As Worksheet
        Dim PTCache As PivotCache
        Dim PT As PivotTable
        Dim PRange As Range
        Dim FinalRow As Long
        Dim FinalCol As Long
        Set WSData = Worksheets("Counter Measures")
        Set WSD = Worksheets("Pivot")
    
        ' Delete any prior pivot tables
        For Each PT In WSD.PivotTables
            PT.TableRange2.Clear
        Next PT
    
        ' Define input area and set up a Pivot Cache
        FinalRow = WSData.Cells(Application.Rows.Count, 1).End(xlUp).Row
        FinalCol = WSData.Cells(1, Application.Columns.Count).End(xlToLeft).Column
        Set PRange = WSData.Cells(1, 1).Resize(FinalRow, FinalCol)
    ''''''''''''''''''''''''''''''''
        Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="=PRange")
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    I get a Reference is not Valid error at the next line.
    
        ' Create the Pivot Table from the Pivot Cache
        Set PT = PTCache.CreatePivotTable(TableDestination:=WSD.Cells(3, 1), TableName:="PivotTable4")
    Last edited by GoPack1; 06-21-2009 at 01:35 PM. Reason: Clarify the title

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