PIvot表的源数据

时间:2019-09-03 12:57:12

标签: excel vba pivot-table

我正在创建VBA代码来创建数据透视表,但是每次运行代码时,数据源的长度都会改变,因此我想根据变量引用它。

Dim SrcData As String

SrcData = "Range(Cells(4,1),Cells(lRowPTF,lColPTF))"

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        SrcData, Version:=6).CreatePivotTable _
        TableDestination:="PT!R3C1", TableName:="PivotTable3", DefaultVersion _:=6

未创建数据透视表。

1 个答案:

答案 0 :(得分:1)

尝试修改以下代码:

Dim SrcRng As Range
Dim SrcData As String

Set SrcRng = Range(Cells(4, 1), Cells(lRowPTF, lColPTF))
SrcData = SrcRng.Address(False, False, xlA1)