+ Reply to Thread
Results 1 to 1 of 1

Creating Pivot Table using VBA

  1. #1
    Registered User
    Join Date
    04-17-2014
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    9

    Creating Pivot Table using VBA

    Hi everyone,

    I am new to VBA and now my main task is to writing VBA. I have to create a pivot table that i have to updated it every week (Attached). I could make it with Insert Pivot Table options but I want it work with VBA (since I have to add new data into the Map Sheet weekly, and later if this works, i would have to connect it with a link from my company website so the data can update automatically). But at this point, I only need your help on creating pivot Table and group by month.

    Here is my code for the attached.

    Sub MakeAPivotTable()

    Dim pt As PivotTable
    Dim cacheOfpt As PivotCache
    Dim pf As PivotField
    Dim pi As PivotItem

    On Error Resume Next
    Sheets("Report").Select
    ActiveSheet.PivotTables("PivotTable1").TableRange2.Clear

    Sheets("Map").Select
    Set cacheOfpt = ActiveWorkbook.PivotCaches.Create(xlDatabase, Table1)

    Sheets("Report").Select
    Set pt = ActiveSheet.PivotTables.Add(cacheOfpt, Range("a1"), "PivotTable1"

    With pt
    .PivotFields("Date Mapped").Orientation = xlRowField
    .PivotFields("Specialist").Orientation = xlColumnField
    .PivotFields("PCMCAT").Orientation = xlDataField
    End With

    End Sub

    Book10.xlsm

    Somehow when I tried to run macros, it didn't popup the Pivot Table. I am not sure what went wrong. Any help would be greatly appreciated.

    Thank you
    Last edited by anoi90; 05-05-2014 at 04:46 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating a Pivot Table using VBA
    By tbone3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2013, 03:51 PM
  2. Replies: 0
    Last Post: 08-09-2013, 12:32 PM
  3. Creating a Pivot Table
    By cstahlhut in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2012, 11:35 PM
  4. Creating a table/array from Pivot Table
    By Roktgr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2010, 07:02 PM
  5. Creating a Pivot Table
    By lkw441 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-07-2005, 12:05 AM

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