Reputation: 33
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.
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?
Upvotes: 1
Views: 1235
Reputation:
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});
}
Upvotes: 2
Reputation: 15328
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()
}
Upvotes: 2