Try this:

Sub CreatePivot()

    Dim wksPivotSheet As Worksheet

    Dim wksWest         As Worksheet

    Set wksPivotSheet = ThisWorkbook.Worksheets.Add

    Dim oPC As PivotCache

    Dim oPT As PivotTable

    Dim oWS As Worksheet

    Set oWS = ActiveSheet

    Set oPC = ActiveWorkbook.PivotCaches.Create(xlDatabase,
Worksheets("West").UsedRange)

    Set oPT = oPC.CreatePivotTable(wksPivotSheet.Range("A1"), "Pivot From
Cache", True)

    oPT.AddFields oPT.PivotFields("Account").Name,
oPT.PivotFields("CostCtr").Name

    oPT.AddDataField oPT.PivotFields("Amount in local cur."), "Amount",
xlSum

    wksPivotSheet.Name = "PivotSummary"

End Sub

 

From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com]
On Behalf Of rekha siri
Sent: Jan/Fri/2012 10:54
To: excel-macros@googlegroups.com
Subject: $$Excel-Macros$$ Re: Need help in building pivot using vba

 

Need pivot macro assistance......

On Wed, Jan 18, 2012 at 9:59 PM, rekha siri <rekha.siri2...@gmail.com>
wrote:

hi experts,

 

Please provide the code to build pivot using vba

 

this macro is provided to me in past by rajan really  thank full for the
concern. 

 

adding to that i need to prepare pivot for  west bu  from attached macro raw
data sheet.

 

pivot format is also attached it should be as per West december2011 file's
pivot manner.

 

attached are macro and west december workbooks which contain pivot ..

 

 

 

kindly help in this concern thanks.

 

Rekha

 

-- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please
Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will
not get quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security
measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum
owners and members are not responsible for any loss.
 
----------------------------------------------------------------------------
--------------------------
To post to this group, send email to excel-macros@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

Reply via email to