I recorded a macro of the creation of a pivot table.
The bit of code that does the business is shown below.
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="'ALL'!R1C2:R1655C7").CreatePivotTable TableDestination:="", _
TableName:="PivotTable1"
My problem is that the SourceData uses fixed cell addresses R1C2 and R1655C7.
I regularly add rows to the data and want rebuild the pivot table. I therefore want to have the code use the values from a variable containing the address of the last cell.
I don't know how to write the SourceData bit so that it uses the variables.
Any help would be greatly appreciated.
The bit of code that does the business is shown below.
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="'ALL'!R1C2:R1655C7").CreatePivotTable TableDestination:="", _
TableName:="PivotTable1"
My problem is that the SourceData uses fixed cell addresses R1C2 and R1655C7.
I regularly add rows to the data and want rebuild the pivot table. I therefore want to have the code use the values from a variable containing the address of the last cell.
I don't know how to write the SourceData bit so that it uses the variables.
Any help would be greatly appreciated.