Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Build Pivot Table with VBA; Keeps Throwing an Error

I keep getting Run-Time Error 5
Invalid Procedure call or argument

The following is hilighted yellow:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
Sheets("C2_UnionQuery").Range("A1").CurrentRegion) .CreatePivotTable _
TableDestination:="[C2_UnionQuery.xls]Summary!R3C1",
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10

I can't figure out what is causing the error...

All data resides on this sheet:
C2_UnionQuery

I am trying to put the Pivot Table on this sheet:
Summary


My code is below:
Sub BuildPT()

Application.ScreenUpdating = False

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If wks.Name = "Summary" Then
Sheets("Summary").Delete

Set ws = Worksheets.Add
'ws.Move After:=Sheets(Sheets.Count)
ws.Name = "Summary"
End If
Next wks

Application.ScreenUpdating = False

Sheets("C2_UnionQuery").Select
Range("A1").Select
'Cells.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
Sheets("C2_UnionQuery").Range("A1").CurrentRegion) .CreatePivotTable _
TableDestination:="[C2_UnionQuery.xls]Summary!R3C1",
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10

Sheets("Summary").Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("RVP")
.Orientation = xlRowField
.Position = 1
End With
'...some more Pivot Fields here...
End Sub


Please help......


Thanks,
Ryan---

--
RyGuy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Build Pivot Table with VBA; Keeps Throwing an Error

Couldn't figure it out, but when I restarted, and thus cleared the memory, it
worked........


--
RyGuy


"ryguy7272" wrote:

I keep getting Run-Time Error 5
Invalid Procedure call or argument

The following is hilighted yellow:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
Sheets("C2_UnionQuery").Range("A1").CurrentRegion) .CreatePivotTable _
TableDestination:="[C2_UnionQuery.xls]Summary!R3C1",
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10

I can't figure out what is causing the error...

All data resides on this sheet:
C2_UnionQuery

I am trying to put the Pivot Table on this sheet:
Summary


My code is below:
Sub BuildPT()

Application.ScreenUpdating = False

Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
If wks.Name = "Summary" Then
Sheets("Summary").Delete

Set ws = Worksheets.Add
'ws.Move After:=Sheets(Sheets.Count)
ws.Name = "Summary"
End If
Next wks

Application.ScreenUpdating = False

Sheets("C2_UnionQuery").Select
Range("A1").Select
'Cells.Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
Sheets("C2_UnionQuery").Range("A1").CurrentRegion) .CreatePivotTable _
TableDestination:="[C2_UnionQuery.xls]Summary!R3C1",
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10

Sheets("Summary").Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("RVP")
.Orientation = xlRowField
.Position = 1
End With
'...some more Pivot Fields here...
End Sub


Please help......


Thanks,
Ryan---

--
RyGuy

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
Different ways to build Pivot table Jan T.[_3_] Excel Discussion (Misc queries) 1 March 3rd 09 08:46 PM
build a pivot table from multiple other pivot tables. Gordo Excel Discussion (Misc queries) 1 December 11th 06 08:19 PM
pivot table build using excel macro jnewl Excel Programming 0 January 16th 06 12:51 PM
How can I build a pivot table from multiple worksheets which are . Richard Stephens Excel Discussion (Misc queries) 2 February 26th 05 10:04 PM
How do you build pivot table in VB Darrell Wesley Excel Programming 1 April 8th 04 02:30 AM


All times are GMT +1. The time now is 04:36 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"