I am running the following function after filling in a row of data on my master sheet (named 'eventlist'). I want the script to create a new sheet with cells that are linked to my master sheet, so that it pulls in data from the row of information I have just entered using ImportRange. But for the purposes of this example, I'm just pulling data from one cell until I get it working...
I am able to create the sheet and send data to a cell. I am also able to draw on my master sheet and have it update the other. But, I'm not able to bring the two together. The code below works up until the 'setValue', I'm ultimately trying to get the final cell to contain the formula '=importrange (relevant sheet and cell range information);' but I'm not sure how to send this formula text and include my row & col variables so that they work alongside it to create the final formula.
Thanks in advance for any pointers!
function addSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getActiveSheet();
var row = sh.getActiveRange().getRowIndex();
var col = sh.getActiveRange().getColumnIndex();
var rData = sh.getRange(row, 1, 1, 3).getValues();
if (row == 1) {
ss.toast("These are column names. You can not send these.");
return
}
if(rData[0][0] != null || rData[0][1] != null || rData[0][2] != null) {
try {
ss.insertSheet(rData[0][0]);
// ss.setActiveSheet(ss.getSheets()[0]);
ss.getRange("D"+(row)).setValue("=importrange("MYSHEETKEY", "eventlist! +col +row : +col +row" )");
} catch(e) {
throw 'Something has gone wrong...';
}
}
}