1

So I made a simple script that duplicates two columns basically. When I run it from the scripteditor I get the correct result, but when I apply this script to a button suddenly it's broken...

Running script

this is the code:

function DuplicateSelectedRows() {
  var spreadsheet = SpreadsheetApp.getActive();

  //Insert rows 
  spreadsheet.getActiveSheet().insertColumns("4");
  spreadsheet.getActiveSheet().insertColumns("4");
  
  // merge cells top
  spreadsheet.getRange('D2:E2').activate()
  .mergeAcross();
  spreadsheet.getRange('D3:E3').activate()
  .mergeAcross();
  
  //paste values in newly created rows
  spreadsheet.getRange('B4:C20').copyTo(spreadsheet.getRange("D4:E20"));
  spreadsheet.getRange('B3:C3').copyTo(spreadsheet.getRange("D3:E3"));
  spreadsheet.getRange('B2:C2').copyTo(spreadsheet.getRange("D2:E2"));
  
  // clear data new training
  spreadsheet.getRange('B5:C20').clearContent();
};

2 Answers 2

3

In your script editor, you are running the script 'DuplicateSelectedRows' but on your button, you are running the script 'NewTraining'

Sign up to request clarification or add additional context in comments.

Comments

0

Although it says "Assign script" what you actually need to put is the name of the Apps Script function you want to link to the image [1], in this case you have to put 'DuplicateSelectedRows'.

[1] https://developers.google.com/apps-script/guides/menus#clickable_images_and_drawings_in_google_sheets

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.