Pretty new to Apps Script.. I have written an Apps script for av lookup and import range and every week I have to update the Spreadsheet URL once the original spreadsheet is generated and then I have to copy and paste that URL into my Apps script to reflect it into the tabs in the spreadsheet. I have 6 Tabs and so I have to copy and paste the URL numerous number of times in each of the script.
Is there a script or a code that I can write so that I only have to Copy and paste the URL for the spreadsheet once.?
This is what I have done..
function Week14() {
//Karen
var ss = SpreadsheetApp.getActive();
var sheet1 = ss.getSheetByName("Karen Z1");
sheet1.getRange("P36:P45").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),3,false)')
sheet1.getRange("P50:P59").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),5,false)')
sheet1.getRange("P64:P73").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),6,false)')
sheet1.getRange("P78:P87").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),8,false)')
sheet1.getRange("P120:P129").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),9,false)')
//Muhamed
var sheet1 = ss.getSheetByName("Muhamed Z2");
sheet1.getRange("P30:P36").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),3,false)')
sheet1.getRange("P41:P47").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),5,false)')
sheet1.getRange("P52:P58").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),6,false)')
sheet1.getRange("P63:P69").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),8,false)')
sheet1.getRange("P96:P102").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),9,false)')
You have to learn JavaScript basic concepts like variables and string concatenation.
var url = 'put here your spreadsheet url';
then instead of
sheet1.getRange("P36:P45").setFormulaR1C1('=vlookup(R[0]C1,importrange("**URL**","SA & NT!E:T"),3,false)')
you could use
sheet1.getRange("P36:P45").setFormulaR1C1('=vlookup(R[0]C1,importrange("' + url + '","SA & NT!E:T"),3,false)')
Do the same for the other statements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.