trying to code a function that, when a menu item is selected, certain data is called and duplicated at the bottom of the open sheet on a spreadsheet - currently the data is being called from an 'Examples' sheet row by row, so I'm trying to pass rowNumber through to the duplicateLastRow function - and currently on this it returns a null value and I can't figure out why.
I'm also very open to different ways of doing this, as my menu has ~80 items, and therefore 80 function definitions, and I feel like 500 lines of code is excessive to copy and paste stuff on command. Code included below, and linked sheet made public here: https://docs.google.com/spreadsheets/d/1yOJ8VdhbkbC9vw5or4geV-mv-PCk-WA86L8-F7-WGM8/edit?usp=sharing The project in script editor is called copyRowFromOriginToDestination, and the script I'm working on is called testFileBlarg - Code2 script is the working but huge version of the code that I'm trying to remove dialog prompts and lines from.
Cheers much in advance!
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('testRow')
.addSubMenu(ui.createMenu('Life Sciences')
.addSubMenu(ui.createMenu('NRG')
.addItem('Highlight/Alamy', 'callHANRG')
))
.addToUi();
}
function callHANRG(rowNumber){
duplicateLastRow(3);
}
function duplicateLastRow(rowNumber){
var originSheetName = "Example Rows";
var ss = SpreadsheetApp.getActiveSpreadsheet(); // This is an object that represents the open spreadsheet
var originSheet = ss.getSheetByName(originSheetName); // This object represents the sheet we are copying FROM
var destinationSheet = ss.getActiveSheet() // getSheetByName(destinationSheetName); // This object represents the sheet we are copying TO
destinationSheet.insertRowAfter(destinationSheet.getLastRow()); // This adds a row to the end of the destination sheet so it doesn't fill up!
var originRow = originSheet.getRange(rowNumber, 1, 1, originSheet.getLastColumn() ); // This object represents the row to be copied
var destinationRow = destinationSheet.getRange(destinationSheet.getLastRow()+1, 1); // This object represents the row we are copying to
originRow.copyTo(destinationRow); // This actions the copying
}