Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Need Help with Sheets Pivot Table Coding

$
0
0

I am trying to code a script to generate a pivot table based on input from drop down menus in Sheets, but I am new to Google Apps Script and having issues understanding the syntax. I am trying to reference cells in worksheet "FORMULAS" which identify the column# or specific filter I want to use for the pivot table, but the Apps Script does not seem to know what to do when I throw in the cell reference. It should work if I can get it to just use the values that appear in the cells referenced in the "FORMULAS" worksheet.

Here is the code:

function PIVOT_TABLE() {var spreadsheet = SpreadsheetApp.getActive();spreadsheet.getRange('E1').activate();var sourceData = spreadsheet.getRange(''SAR2021'!A1:AD3198');var pivotTable = spreadsheet.getRange('E1').createPivotTable(sourceData);pivotValue = pivotTable.addCalculatedPivotValue('WIN%', '=WIN/(WIN+LOSS)');pivotValue = pivotTable.addCalculatedPivotValue('WINS', '=WIN');pivotValue = pivotTable.addCalculatedPivotValue('RACES', '=WIN+LOSS');pivotGroup = pivotTable.addRowGroup(''FORMULAS'!I5');pivotGroup.showTotals(false);pivotGroup = pivotTable.addRowGroup(''FORMULAS'!I7');pivotGroup.showTotals(false);pivotGroup = pivotTable.addColumnGroup(''FORMULAS'!I2');pivotGroup.showTotals(false);criteria = SpreadsheetApp.newFilterCriteria().setVisibleValues([''FORMULAS'!I3']).build();pivotTable.addFilter(''FORMULAS'!I5', criteria);criteria = SpreadsheetApp.newFilterCriteria().setVisibleValues([''FORMULAS'!I6']).build();pivotTable.addFilter(''FORMULAS'!I7', criteria);criteria = SpreadsheetApp.newFilterCriteria().setVisibleValues([''FORMULAS'!I8']).build();};


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>