0

为我每周运行的包含数据透视表的报告录制了一个宏。问题是每周的范围都不一样。我尝试仅为列设置参数,但由于数据下方的所有空白单元格,我在数据透视表中得到一个空白列。有没有办法改变 SourceData:= _ "UBS Pre-Orders Report!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
4

0 回答 0