'Google Spreadsheet, select range from activecell
I am new to google spreadsheets and i fail finding the answer to my question. I want to cut an range (from the active cell, 5 cells to the right) and paste it on the other sheet.
I know now that to reference to the currrently active cell you have to use .getCurrentCell
var range = SpreadsheetApp.getActive().getCurrentCell();
I want to write a script that selects the activecell and the next 5 cells on the right. Therefore you could use
var range = SpreadsheetApp.getActiveSheet().getRange(1,1,1,5);
Problem is, I can't put the range (currentCell) in the getRange
Then I want to cut them and transport them to another sheet. Therefore I could use
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
var lastrow = sheet2.getLastRow() + 1;
sheet2.getRange(lastrow, 1).setValue('Jan');
Problem is, I can't put the range in de setValue
Is there anyone who could help me out (suggestions, directions, no complete code) here?
Thanks in advance, Jan
Solution 1:[1]
I figured something out, but wonder if it could be more efficient.
function copyOffsetFromCurrentCellPaste()
{
var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var lastrow = sheet1.getLastRow() + 1;
var currentcell = SpreadsheetApp.getCurrentCell();
var row = currentcell.getRow();
var rownumbers = 1
var column = currentcell.getColumn();
var columnnumbers = 5
var values = SpreadsheetApp.getActiveSheet().getRange(row, column,
rownumbers, columnnumbers).getValues();
sheet1.getRange(lastrow, 1, 1, 5).setValues(values);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | General Grievance |
