Skip to content

Instantly share code, notes, and snippets.

@j100002ben
Created March 10, 2013 19:48
Show Gist options
  • Save j100002ben/5130126 to your computer and use it in GitHub Desktop.
Save j100002ben/5130126 to your computer and use it in GitHub Desktop.
/**
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function onOpen() {
var sheet = SpreadsheetApp.getActiveSheet();
var b_col = sheet.getRange('B:B');
var g_col = sheet.getRange('G:G');
var num_rows = g_col.getNumRows();
Logger.log(num_rows);
var values = g_col.getValues();
var formulas = [];
for (var i = 0; i < num_rows; i++){
Logger.log(values[i][0]);
formulas[i] = formulas[i] || [];
if (values[i][0] != ''){
formulas[i][0] = '=G' + (i+1).toString();
}else{
formulas[i][0] = '';
}
}
b_col.setFormulas(formulas);
};
@joeangel
Copy link

bravo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment