I'm trying to create a custom function so that I can dynamically return all the tabs within a spreadsheet to use within the QUERY
function.
So that in the future if I add a new tab of data, I won't need to manually update the function.
function myFunction() {
var out = new Array();
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i=0 ; i<sheets.length ; i++) {
var name = sheets[i].getName();
if (i !== sheets.length - 1) {
out.push("'"+sheets[i].getName()+ "'!$A:$F; " );
} else {
out.push("'"+sheets[i].getName()+ "'!$A:$F " );
}
}
return out;
}
Example of how I will use my custom function
=query(myFunction(),"select * where Col4 = 'Partner' order by Col1 desc",0)