Nothing has made me more frustrated with VBA than pivot tables. I would like to simply specify a data source for a pivot table using VBA.
Dim pvtcache As PivotCache
Dim Range1 As Range
ActiveSheet.PivotTables("PivotTable4").ChangePivotCache _
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
ThisWorkbook.Worksheets("Business Process Identification").Range("A1:Bc1693").Address(ReferenceStyle:=xlR1C1) _
, Version:=6)
I'm trying to open a workbook from a SP site, and then reference data for the data source, refresh, then close the workbook.
I get a runtime error '-2147024809' that says: "the PivotTable field name is not valid. To create a PivotTable report, you must use data that is organized as a list with labeled columns. IF you are changing the name of a PivotTable field, you must type a new name for the field"
If I manually change the data source to the range specified in the code, there is no problems, only when I run this macro.
Note: The reference data for right now is in the same workbook, and I'm getting this same error. Note: I do not have hidden columns or rows, I have all my column headers labelled correctly, which is the usual cause of this problem
ListObject
as a data source, you never need to quadruple-check you're capturing all the rows ever again. – Mathieu Guindon=OFFSET(SHEETNAME!A1,0,0,COUNTA(SHEETNAME!A:A),COUNTA(SHEETNAME!1:1))
this will give you a dynamic range growing with the sheet, thought you will need to open the other workbook to refresh it but... – Damian