我正在创建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
未创建数据透视表。
答案 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)