Skip to content

Instantly share code, notes, and snippets.

@mjdebeer
Created June 16, 2020 17:39
Show Gist options
  • Save mjdebeer/ac3afa3340cd71ff7153530390e3c595 to your computer and use it in GitHub Desktop.
Save mjdebeer/ac3afa3340cd71ff7153530390e3c595 to your computer and use it in GitHub Desktop.
/* Global variables */
const ss = SpreadsheetApp.openById('1zumu5PGT0HJDM8ceErBaldfr1kN2-i1L0sAwT_1WjYc');
const gid = ss.getSheetId();
const artists = ss.getSheets()[0];
const template = ss.getSheets()[1];
function copyFormat() {
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(2, 1, 1, lastColumn).copyFormatToRange(sheet, 1, sheet.getLastColumn(), 3, sheet.getLastRow());
}
function getCellValue(sheet, col, row){
const range = ss.getRange(col + row);
const selection = ss.getSelection();
ss.setActiveSheet(sheet);
range.activate();
return selection.getCurrentCell();
}
function newSheetOnSubmit() {
const name = getCellValue(artists,"C", ss.getLastRow());
const surname = getCellValue(artists, "D", ss.getLastRow());
const id = getCellValue(artists,"A", ss.getLastRow());
const idDestOne = ss.getRange('H' + ss.getLastRow());
const idDestTwo = ss.setActiveSheet(ss.getSheets()[2]);
// Create new sheet and rename to artist name and surname
ss.setActiveSheet(template);
ss.duplicateActiveSheet();
ss.setActiveSheet(ss.getSheets()[2]);
ss.renameActiveSheet(name + " " + surname);
// Paste ID to Artists sheet
idDestOne.setValue('=HYPERLINK("#gid=' + gid + '"' + ',' + '"Session Sheet"' + ')');
// Paste ID to new created sheet sheet
id.copyTo(idDestTwo.getRange('B1'), {contentsOnly:true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment