Home > Blockchain >  How to Ctrl Shift Down using Google app scripts
How to Ctrl Shift Down using Google app scripts

Time:01-28

I am trying to write an Google App Script for a google sheet that I have. The number of values I have in column D will change every week, and I am trying to copy those values to paste into another sheet.

enter image description here

So far, I can't find any code that will do the equivalent of selecting D2, and doing a Ctrl Shift down copy.

function ELATerminationTransfer() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('D2').activate();SpreadsheetApp.getSelection().getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate};

Anyone know of a simple fix?

CodePudding user response:

You can select by this way

function myFunction(){
  var cel = SpreadsheetApp.getActiveRange()
  var end = cel.getNextDataCell(SpreadsheetApp.Direction.DOWN)
  var rng = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(cel.getA1Notation() ':' end.getA1Notation()).activate()
}

CodePudding user response:

Try this:

function testSelection()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sourceSheet = ss.getSheetByName('Source');
  var destSheet = ss.getSheetByName('Destination');

  // copy column values to destination sheet
  sourceSheet
    .getRange('D2:D')
    .copyTo(destSheet.getRange('D2'), {contentsOnly:true});
}
  •  Tags:  
  • Related