+ Reply to Thread
Results 1 to 3 of 3

Pivot Table Creation

  1. #1
    Rob
    Guest

    Pivot Table Creation

    I'm having trouble programatically creating a pivot table. If I step through
    the code below it works, but if I run it, it falls over on the Set PT line.
    Can anyone see a problem with my code?
    Thanks
    Rob

    Sub MakePivot(ReportName As String, DataAddress As String, ReportAddress As
    Range)

    Dim PTcache As PivotCache
    Dim PT

    Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
    SourceData:=DataAddress)
    Set PT = PTcache.CreatePivotTable(TableDestination:=ReportAddress,
    TableName:=ReportName)


  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    I usually find it easiest to cheat and record the creation of a pivot table, then tweak the pivottablewizard code... it's inelegant, but it saves a lot of time!

    Col

  3. #3
    Rob
    Guest

    RE: Pivot Table Creation

    I found the solution. If anyone's interested then here's what was happening:

    The DataAddress parameter being passed to the function did not include the
    sheet name. (ie. it was something like "A1:H50"). When stepping through,
    excel had time to resolve this address as referring to the active sheet, but
    when Running, it did not.

    Regards
    Rob




    "Rob" wrote:

    > I'm having trouble programatically creating a pivot table. If I step through
    > the code below it works, but if I run it, it falls over on the Set PT line.
    > Can anyone see a problem with my code?
    > Thanks
    > Rob
    >
    > Sub MakePivot(ReportName As String, DataAddress As String, ReportAddress As
    > Range)
    >
    > Dim PTcache As PivotCache
    > Dim PT
    >
    > Set PTcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
    > SourceData:=DataAddress)
    > Set PT = PTcache.CreatePivotTable(TableDestination:=ReportAddress,
    > TableName:=ReportName)
    >


+ 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