PC Review


Reply
Thread Tools Rate Thread

Creating a Pivot Table via Macro - Errors on Recorded Code

 
 
JG
Guest
Posts: n/a
 
      2nd Jun 2010
I have an Excel workbook that is getting generated from another tool (Quality
Center). It has output data on a tab called "FailedBlocked" and another tab
that is empty called "TC by Def".

I have recorded a macro to create the pivot table. The code Excel creates is:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"FailedBlocked!R1C1:R1090C13", Version:=xlPivotTableVersion10). _
CreatePivotTable TableDestination:="TC by Def!R1C1", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10

Sheets("TC by Def").Select
Cells(1, 1).Select

When I run the macro, I am getting an "Invalid procedure call or argument
(Error 5)" message. Is the code somehow malformed on record? What could be
invalid here (should I remove spaces from my sheet names? Should that
matter?)?

Thanks.
 
Reply With Quote
 
 
 
 
JG
Guest
Posts: n/a
 
      2nd Jun 2010
Forgot to mention... I'm in Excel 2007.

Thanks again!
 
Reply With Quote
 
Javed
Guest
Posts: n/a
 
      3rd Jun 2010
On Jun 3, 1:31*am, JG <J...@discussions.microsoft.com> wrote:
> Forgot to mention... I'm in Excel 2007.
>
> Thanks again!


You must have run it more than once.In excel In one cell only 1
pivottable can be pasted and the table name also should be unique.


TableDestination:="TC by Def!R1C1"-----This should change with each
run
TableName:="PivotTable1"-----This should change with each run
 
Reply With Quote
 
JG
Guest
Posts: n/a
 
      3rd Jun 2010
I figured out what the problem was and am posting it here to help others in
the future:

The problem lies here in the part of the code that reads:
TableDestination:="TC by Def!R1C1"

Now, mind you, this is generated by Excel. Since the sheet name has spaces
in it, Excel should have encapsulated TC by Def with single quotes.

As soon as I change that part of the code to:
TableDestination:="'TC by Def'!R1C1"

It works. Every time.

Javed, thanks for your input, but I was running the code on spreadsheets
that had not yet had the pivot table run (same data set, new file).

"JG" wrote:

> I have an Excel workbook that is getting generated from another tool (Quality
> Center). It has output data on a tab called "FailedBlocked" and another tab
> that is empty called "TC by Def".
>
> I have recorded a macro to create the pivot table. The code Excel creates is:
>
> ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
> "FailedBlocked!R1C1:R1090C13", Version:=xlPivotTableVersion10). _
> CreatePivotTable TableDestination:="TC by Def!R1C1", TableName:= _
> "PivotTable1", DefaultVersion:=xlPivotTableVersion10
>
> Sheets("TC by Def").Select
> Cells(1, 1).Select
>
> When I run the macro, I am getting an "Invalid procedure call or argument
> (Error 5)" message. Is the code somehow malformed on record? What could be
> invalid here (should I remove spaces from my sheet names? Should that
> matter?)?
>
> Thanks.

 
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
excel 2007 macro recorded pivot table getting old Microsoft Excel Worksheet Functions 2 19th Apr 2010 09:06 AM
macro creating new pivot table Pjvicente Microsoft Excel Programming 2 11th Mar 2009 10:06 AM
problem creating a pivot table using a macro vrzimmerm@hotmail.com Microsoft Excel Programming 2 27th Mar 2007 11:40 AM
creating a macro with a pivot table =?Utf-8?B?Sm9zaCBNYWNoaW5l?= Microsoft Excel Crashes 0 22nd Nov 2005 10:53 PM
Help with a macro creating a formula for a pivot table =?Utf-8?B?VmFsZXJpYQ==?= Microsoft Excel Programming 1 20th Nov 2004 12:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:26 AM.