Skip to content

Instantly share code, notes, and snippets.

@MitMaro
Created December 24, 2012 04:37
Show Gist options
  • Save MitMaro/4367554 to your computer and use it in GitHub Desktop.
Save MitMaro/4367554 to your computer and use it in GitHub Desktop.
Google Docs - Duplicate Row Down Script
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "Duplicate Selected Row Down", functionName: "duplicate_row_down"},];
ss.addMenu("Utilities",menuEntries);
}
function duplicate_row_down (){
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var d = ss.getActiveSelection();
sh.insertRowAfter(d.getLastRow());
// copy formula
var new_range = sh.getRange(d.getLastRow()+1, 1, 1, d.getLastColumn())
new_range.setFormulasR1C1(d.getFormulasR1C1());
// copy formatting
d.copyTo(new_range, {formatOnly:true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment