![](/img/trans.png)
[英]Excel VBA: Active Selection as a Named Range for Pivot Table Data Source
[英]How to select dynamic range(from active selection) of data source for pivot table
幫我從選擇中獲取我的數據透視表的源數據
Sheets("Filtered Data").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
我的選擇過程到此結束,數據透視表選擇數據,您能幫助我使其動態嗎?
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Filtered Data!R1C1:R21C8", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Snap!R6C6", TableName:="PivotTable13", DefaultVersion _
:=xlPivotTableVersion15
格式化數據透視表在那里填充不是那么重要
Sheets("Snap").Select
Cells(6, 6).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable13").PivotFields("CMP")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable13").PivotFields("Area")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable13").AddDataField ActiveSheet.PivotTables( _
"PivotTable13").PivotFields("Site Name"), "Count of Site Name", xlCount
ActiveWorkbook.ShowPivotTableFieldList = False
Columns("F:K").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
嘗試類似:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:= Sheets("Filtered Data").Range("A1").CurrentRegion, _
Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Snap!R6C6", TableName:="PivotTable13", DefaultVersion _
:=xlPivotTableVersion15
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.