RRinTetons
IS-IT--Management
I have a worksheet that queries data from a SQL Server database. The query returns a fixed number of columns and varying numbers of rows. After the data gets to Excel I select it and make a pivot table out of it. Here's the line I use to create the PT
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!CompQueryFromJHMRCustom_13").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
Notice the named range used as the range for the PT - that's the name of the query return. The problem is that it increments each time the query runs - <name>_01 ... <name>_xx.
How can I get a consistent range argument for the pivot table? Rename the range somehow each time the query runs? Figure out the new name and reference it in the statement above? Some other good idea?
-
Richard Ray
Jackson Hole Mountain Resort
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!CompQueryFromJHMRCustom_13").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
Notice the named range used as the range for the PT - that's the name of the query return. The problem is that it increments each time the query runs - <name>_01 ... <name>_xx.
How can I get a consistent range argument for the pivot table? Rename the range somehow each time the query runs? Figure out the new name and reference it in the statement above? Some other good idea?
-
Richard Ray
Jackson Hole Mountain Resort