PC Review


Reply
Thread Tools Rate Thread

Creating a Pivot Table with a named range

 
 
tkpmep@hotmail.com
Guest
Posts: n/a
 
      4th Apr 2008
I'm having trouble creating a Pivot Table with a named range. My code
follows, and guidance on the cause of my error will be greatly
appreciated.


Sub CreateHeadersAndPivotTable()
Dim PTCache As PivotCache
Dim PT1 As PivotTable

Col = 15


Range(Sheet23.Cells(1, Col), Sheet23.Cells(1,
Col).End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Name = "Data"

Set PTCache =
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
SourceData:="Data")
Set PT1 =
ActiveWorkbook.ActiveSheet.PivotTables.Add(PivotCache:=PTCache, _
TableDestination:=Sheet23.Cells(5, Col +
10))

end sub

It's not clear to me if I create a range named Data, because the code
stosp at the next line (Set PTCache = ..) with the error message Run
time errror 438, Object doesn't support this porperty or method.

Thanks in advance for your assistance.

Sincerely

Thomas Philips
 
Reply With Quote
 
 
 
 
tkpmep@hotmail.com
Guest
Posts: n/a
 
      4th Apr 2008
It seems I have a partial solution: I had to ADD, not CREATE a
PivotCache, i.e. I can get the following line to work:
Set PTCache =
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:="Data")

Moreover, the range data is good - I can for example create a watch on
Range("Data").Cells(1,1).Value, and I get the rgiht result

But the next line still results in an error: Run-time Error 1004:
Application Defined or object-defined error.

ActiveWorkbook.ActiveSheet.PivotTables.Add(PivotCache:=PTCache,
TableDestination:=Sheet23.Cells(5, Col + 10))

Any thoughts? googling has not got me an answer.

Sincerely

Thomas Philips

 
Reply With Quote
 
tkpmep@hotmail.com
Guest
Posts: n/a
 
      4th Apr 2008
Got the rest of it - I had to clear the existing pivot table as the
new one was overwriting it. Had to run the following code before
creating the pivot table:

With Sheet23
For Each p In .PivotTables
p.TableRange2.Clear
Next
End With
 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      7th Apr 2008
I encountered a similar issue recently.
Check this out
http://www.microsoft.com/office/comm...sloc=en-us&p=1

Your situation will be slightly different, but I believe the concept is the
same.

Regards,
Ryan----

--
RyGuy


"(E-Mail Removed)" wrote:

> I'm having trouble creating a Pivot Table with a named range. My code
> follows, and guidance on the cause of my error will be greatly
> appreciated.
>
>
> Sub CreateHeadersAndPivotTable()
> Dim PTCache As PivotCache
> Dim PT1 As PivotTable
>
> Col = 15
>
>
> Range(Sheet23.Cells(1, Col), Sheet23.Cells(1,
> Col).End(xlToRight)).Select
> Range(Selection, Selection.End(xlDown)).Name = "Data"
>
> Set PTCache =
> ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
> SourceData:="Data")
> Set PT1 =
> ActiveWorkbook.ActiveSheet.PivotTables.Add(PivotCache:=PTCache, _
> TableDestination:=Sheet23.Cells(5, Col +
> 10))
>
> end sub
>
> It's not clear to me if I create a range named Data, because the code
> stosp at the next line (Set PTCache = ..) with the error message Run
> time errror 438, Object doesn't support this porperty or method.
>
> Thanks in advance for your assistance.
>
> Sincerely
>
> Thomas Philips
>

 
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
create a pivot table and chart from a named range SS Microsoft Excel Programming 1 7th Jun 2011 04:43 AM
not your typical Pivot Table Named Range question Dick Watson Microsoft Excel Discussion 7 21st Jul 2009 04:24 AM
Creating a pivot table using all named ranges excelguru Microsoft Excel Programming 2 29th Feb 2004 11:21 AM
Re: Pivot Table - Named Range JMay Microsoft Excel Misc 1 24th Nov 2003 05:38 PM
Pivot tables, linking to a named range as a source to a pivot table Karen Microsoft Excel Misc 1 18th Oct 2003 01:45 PM


Features
 

Advertising
 

Newsgroups
 


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