Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Programming a macro in Excel Office 2007 to create Pivot Table

In Excel 97-2003, I had created in a macro to create a pivot table from a
range of data. However, when I converted the file to Excel in Office 2007, I
get VBA errors.
The converted workbook is now an xlsm file with macros enabled.

Not sure what else to do. The VBA error is:

Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDa tabase, SourceData:= _
"Loans!R8C2:R416C55",
Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable1",
DefaultVersion _
:=xlPivotTableVersion12
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Programming a macro in Excel Office 2007 to create Pivot Table

Steve,

Obviously, I don't have your data set to test the PivotTable, but I used
some mock data and didn't receive an error (i.e. I used your code and
replaced the appropriate arguments). I would try your code again, or you can
reference some illustrative code below which utilizes the object module to
create the PivotTable.

Best,

Matthew Herbert

Sub SampleCreatePivotTable()
Dim Wkb As Workbook
Dim Wks As Worksheet
Dim pvtCache As PivotCache
Dim pvtTbl As PivotTable
Dim rngSourceData As Range

Set Wkb = ThisWorkbook
'you can use .CurrentRegion or combination of .End
' to set the source data range
With Wkb
Set rngSourceData = .Worksheets(1).Range("A1:C10")
Set Wks = .Worksheets.Add
End With

With Wkb
Set pvtCache = .PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:=rngSourceData, _
Version:=xlPivotTableVersion12)

Set pvtTbl = pvtCache.CreatePivotTable(TableDestination:= _
Wks.Range("A1"))

With pvtTbl
With .PivotFields("Date")
.Orientation = xlRowField
.Position = 1
End With


With .PivotFields("File Name")
.Orientation = xlColumnField
.Position = 1
End With

.AddDataField .PivotFields("Value"), "Sum of Value", xlSum
.RowGrand = False
.ColumnGrand = False
End With

.ShowPivotTableFieldList = False
End With

End Sub


"Steve C." wrote:

In Excel 97-2003, I had created in a macro to create a pivot table from a
range of data. However, when I converted the file to Excel in Office 2007, I
get VBA errors.
The converted workbook is now an xlsm file with macros enabled.

Not sure what else to do. The VBA error is:

Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDa tabase, SourceData:= _
"Loans!R8C2:R416C55",
Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable1",
DefaultVersion _
:=xlPivotTableVersion12

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
Office 2007 and Pivot Table Trouble Erika Excel Discussion (Misc queries) 1 May 30th 09 02:19 AM
How-to create a list from a summary table? (Office 2007) Mikael Lindqvist Excel Worksheet Functions 2 January 18th 08 01:00 PM
Office 2007 compatible with Office 2000 macro programming Mervyn Thomas Excel Programming 2 November 27th 07 12:24 PM
Excel 2007: Create a pivot table where data is in multible sheets Kenneth Andersen Excel Worksheet Functions 12 May 14th 07 07:25 AM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"