0

I am trying to create a button (position should be fixed, so the button stays visible even when I scroll down sheet). I was able to draw it but now I stuck in the step of setting button up for this:

  • After clicking on the button, it should add a new line (as line 16). In date fields, I would like to get prefilled today's date. Other fields should be blank.
  • Line 15 is older line with inserted and chosen data from the dropdown list and date field.

enter image description here

Any idea, please?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
peter
  • 4,289
  • 12
  • 44
  • 67

1 Answers1

1

I found an answer by myself:

// global 
var ss = SpreadsheetApp.getActive();

function my(){       
  var sh = ss.getActiveSheet(), lRow = sh.getLastRow(), mylastrow=lRow + 1; 
  var lCol = sh.getLastColumn(), range = sh.getRange(lRow,1,1,lCol);
  sh.insertRowsAfter(lRow, 1);
  range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});

  SpreadsheetApp.getActiveSheet().getRange('A'+mylastrow).setValue('');
  SpreadsheetApp.getActiveSheet().getRange('B'+mylastrow).setValue(new Date());
  SpreadsheetApp.getActiveSheet().getRange('C'+mylastrow).setValue('0');
  SpreadsheetApp.getActiveSheet().getRange('D'+mylastrow).setValue('');
  SpreadsheetApp.getActiveSheet().getRange('E'+mylastrow).setValue(new Date());
  SpreadsheetApp.getActiveSheet().getRange('F'+mylastrow).setValue('');
  SpreadsheetApp.getActiveSheet().getRange('G'+mylastrow).setValue('');
}
peter
  • 4,289
  • 12
  • 44
  • 67