Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,388
Default Pivot Table from Macro

I am trying to produce a pivot table using a macro.

I have the following:

Sub Macro4()
'
' Macro4 Macro
'
Lastrow = Cells.SpecialCells(xlCellTypeLastCell).Row
Range("A1").PivotCaches.Add(SourceType:=xlDatabase ,
SourceData:="'Average Deployment'!R1:R" & Lastrow).CreatePivotTable
TableDestination:="", TableName:="PivotTable10",
DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable10").AddFields
RowFields:=Array("Year", "Quarter")
With ActiveSheet.PivotTables("PivotTable10").PivotField s("Number of Days")
.Orientation = xlDataField
.Caption = "Average of Number of Days"
.Function = xlAverage
End With
Range("A4").Group Start:=True, End:=True, Periods:=Array(False, False,
False, _
False, False, False, True)
Columns("C:C").NumberFormat = "0"
End Sub

But I get error: Run Time Error 438, Object doesn't support this property or
method.

Can anyone tell me where I am going wrong?

Thanks
Dave
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Pivot Table from Macro

Which line generates the error?
--
HTH...

Jim Thomlinson


"Dave" wrote:

I am trying to produce a pivot table using a macro.

I have the following:

Sub Macro4()
'
' Macro4 Macro
'
Lastrow = Cells.SpecialCells(xlCellTypeLastCell).Row
Range("A1").PivotCaches.Add(SourceType:=xlDatabase ,
SourceData:="'Average Deployment'!R1:R" & Lastrow).CreatePivotTable
TableDestination:="", TableName:="PivotTable10",
DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable10").AddFields
RowFields:=Array("Year", "Quarter")
With ActiveSheet.PivotTables("PivotTable10").PivotField s("Number of Days")
.Orientation = xlDataField
.Caption = "Average of Number of Days"
.Function = xlAverage
End With
Range("A4").Group Start:=True, End:=True, Periods:=Array(False, False,
False, _
False, False, False, True)
Columns("C:C").NumberFormat = "0"
End Sub

But I get error: Run Time Error 438, Object doesn't support this property or
method.

Can anyone tell me where I am going wrong?

Thanks
Dave

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,388
Default Pivot Table from Macro

http://www.excelforum.com/showthread...=1#post1852140

I think my problem has been fixed here.
Thanks Guys for your time.

"Jim Thomlinson" wrote:

Which line generates the error?
--
HTH...

Jim Thomlinson


"Dave" wrote:

I am trying to produce a pivot table using a macro.

I have the following:

Sub Macro4()
'
' Macro4 Macro
'
Lastrow = Cells.SpecialCells(xlCellTypeLastCell).Row
Range("A1").PivotCaches.Add(SourceType:=xlDatabase ,
SourceData:="'Average Deployment'!R1:R" & Lastrow).CreatePivotTable
TableDestination:="", TableName:="PivotTable10",
DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable10").AddFields
RowFields:=Array("Year", "Quarter")
With ActiveSheet.PivotTables("PivotTable10").PivotField s("Number of Days")
.Orientation = xlDataField
.Caption = "Average of Number of Days"
.Function = xlAverage
End With
Range("A4").Group Start:=True, End:=True, Periods:=Array(False, False,
False, _
False, False, False, True)
Columns("C:C").NumberFormat = "0"
End Sub

But I get error: Run Time Error 438, Object doesn't support this property or
method.

Can anyone tell me where I am going wrong?

Thanks
Dave

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
Pivot Table by Macro? Roger Converse Charts and Charting in Excel 0 November 7th 07 09:56 PM
Is it possible to Macro a Pivot Table? jeannie v Excel Worksheet Functions 2 July 22nd 07 01:56 AM
Pivot Table Macro BCNU Excel Discussion (Misc queries) 0 November 14th 06 01:33 AM
MACRO FOR PIVOT TABLE anu Excel Discussion (Misc queries) 2 August 11th 06 05:07 PM
Macro to change a Pivot Table David M Excel Discussion (Misc queries) 0 March 22nd 05 05:27 PM


All times are GMT +1. The time now is 06:49 AM.

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"