PC Review


Reply
Thread Tools Rate Thread

Build Pivot Table with VBA; Keeps Throwing an Error

 
 
ryguy7272
Guest
Posts: n/a
 
      23rd Jul 2008
I keep getting Run-Time Error 5
Invalid Procedure call or argument

The following is hilighted yellow:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, 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:=xlDatabase, 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 With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      23rd Jul 2008
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:=xlDatabase, 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:=xlDatabase, 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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Different ways to build Pivot table Jan T. Microsoft Excel Misc 1 3rd Mar 2009 08:46 PM
build a pivot table from multiple other pivot tables. Gordo Microsoft Excel Misc 0 11th Dec 2006 06:56 PM
run error 1004 - error when trying to build a pivot table thru an =?Utf-8?B?am5ld2w=?= Microsoft Excel Crashes 2 5th May 2005 05:12 PM
Table.Rows.Add with expression on columns throwing error Joe Microsoft ADO .NET 1 28th Jan 2005 08:32 PM
How do you build pivot table in VB =?Utf-8?B?RGFycmVsbCBXZXNsZXk=?= Microsoft Excel Programming 1 8th Apr 2004 02:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:25 PM.