你能在VBA中更改数据透视表的源代码吗?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了你能在VBA中更改数据透视表的源代码吗?相关的知识,希望对你有一定的参考价值。
为每周运行一次包含数据透视表的报告记录了一个宏。问题是每周的范围不一样。我尝试仅为列设置参数,但由于数据下方的所有空白单元格,我在数据透视表中得到一个空白列。有没有办法更改SourceData:= _“UBS预购报告!R1C1:R1048576C19”(
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"UBS Pre-Orders Report!R1C1:R1048576C19", Version:=6).CreatePivotTable _
TableDestination:="Sheet4!R3C1", TableName:="PivotTable2", DefaultVersion _
:=6
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2")
.ColumnGrand = True
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = True
.SaveData = True
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = False
.CompactRowIndent = 1
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = False
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.FieldListSortAscending = False
.ShowValuesRow = False
.CalculatedMembersInFilters = False
.RowAxisLayout xlCompactRow
End With
With ActiveSheet.PivotTables("PivotTable2").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("PivotTable2").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Item Number")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Quantity On Order"), "Sum of Quantity On Order", _
xlSum
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Ship Date")
.Orientation = xlColumnField
.Position = 1
End With
End Sub
答案
我在这里使用了这篇文章,它让我得到了我需要的地方,它基本上将范围设置为一个表,然后使用Table作为源代码https://chandoo.org/wp/tables-pivottables-and-macros-music-to-your-ears/
以上是关于你能在VBA中更改数据透视表的源代码吗?的主要内容,如果未能解决你的问题,请参考以下文章