I am creating a VBA code to create a Pivot Table, but my source of data change of length each time I want to run the code, so I would like to reference it according to a variable.
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
The pivot table is not created.
=OFFSET(SHEETNAME!A1,0,0,COUNTA(SHEETNAME!A:A),COUNTA(SHEETNAME!1:1))this way you will have a dynamic source which will grow with your data. - Damian