Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default set pivottable source data to range name

PBCorn,

There is some sample code that will generate a PivotTable on a worksheet. I
don't know where you want your pivot table or where your pivot table data is
located, so you'll need to adjust the code accordingly. The code was
generated in Office 2007.

Best,

Matthew Herbert

Dim Wkb As Workbook
Dim Wks As Worksheet
Dim pvtCache As PivotCache
Dim pvtTbl As PivotTable
Dim rngSourceData As Range

'you can use .CurrentRegion or combination of .End
'to set the source data range
Set rngSourceData = Worksheets("XYZ").Range("A1:C10")
Set Wks = Worksheets.Add
Set Wkb = Wks.Parent

With Wkb
Set pvtCache = .PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
rngSourceData, Version:=xlPivotTableVersion12)

Set pvtTbl = pvtCache.CreatePivotTable(TableDestination:=Wks.Ra nge("A1"))

With pvtTbl
With .PivotFields("Date")
.Orientation = xlRowField
.Position = 1
End With

With .PivotFields("File Name")
.Orientation = xlColumnField
.Position = 1
End With

.AddDataField .PivotFields("Value"), "Sum of Value", xlSum
.RowGrand = False
.ColumnGrand = False
End With

.ShowPivotTableFieldList = False
End With


"PBcorn" wrote:

I have a pivottable which i need to link to a range name set within a macro,
i.e. macro runs, sets range variable, pivottable sourcedata equals this,
refresh pivottable.

what is the best way of doing this as i can't seem to do it without running
the wizard?

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
what types of source data can't be grouped in pivottable Group items in a PivotTable Excel Discussion (Misc queries) 0 September 2nd 09 10:31 AM
Dynamic PivotTable Data Source Lenardz Excel Discussion (Misc queries) 1 August 22nd 07 08:08 PM
PivotTable with No Source Data [email protected] Excel Programming 5 January 23rd 06 05:42 PM
Select different source data for a PivotTable chetoos Excel Worksheet Functions 1 September 8th 05 07:14 PM
How to source data from multiple worksheets in a PivotTable? Wally Excel Programming 2 December 9th 04 09:21 AM


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"