Hi, I'm attempting to create a pivot table using a list table as the datasource, and if I filter the source table, then I would like the pivot table to reflect the same filter. My thinking is that the source range is defined as visible cells only.
Code fragments:
Create dynamic range (to accommodate changes in the amount of data being placed on the worksheet):
Create table from (dynamic) range:
Create pivot table:
Using "specialcells(xlvisible)" is my attempt to achieve my objective, but although the pivot table is created successfully, when I filter the source table, the pivot table does not change on refresh.
Can anyone suggest a way forward (or sideways)?
Mike
Code fragments:
Create dynamic range (to accommodate changes in the amount of data being placed on the worksheet):
Code:
WITH loworkbook.ActiveSheet
[indent]* lnFCount gives number of columns in the data range
lncols = lnFCount - 1
*include column headings
.Names.Add("data", "=OFFSET(Data!$a$1,0,0,COUNTA(Data!$A:$A),"+TRANSFORM(lncols+1)+")")
[/indent]
ENDWITH
Create table from (dynamic) range:
Code:
WITH loworkbook.ActiveSheet
[indent].ListObjects.Add(xlSrcRange, .Range("data!data"), , xlYes).Name = "Table1"
[/indent]
ENDWITH
loSet = losheet.ListObjects("Table1")
Create pivot table:
Code:
WITH loExcel.ActiveWorkbook
[indent]* loset.range refers to the entire list table
.PivotCaches.Create(xlDatabase,loset.range.specialcells(xlvisible),xlPivotTableVersion10);
.CreatePivotTable("Pivot!R7C1","PivotTable",xlPivotTableVersion10) && Destination ref (must use r1c1 ref style), PT name, version
[/indent]
ENDWITH
Using "specialcells(xlvisible)" is my attempt to achieve my objective, but although the pivot table is created successfully, when I filter the source table, the pivot table does not change on refresh.
Can anyone suggest a way forward (or sideways)?
Mike