Reputation: 79
I'm sure it's simple but i'm trying to get it to paste the data in Column U first blank cell. It's currently pasting in Column A starting from cell A28.
function Update() {
var sheet = SpreadsheetApp.getActiveSheet();
var values = sheet.getRange("U:U").getValues();
var maxIndex = values.reduce(function(maxIndex, row, index) {
return row[0] === "" ? maxIndex : index;
}, 0);
sheet.setActiveRange(sheet.getRange(maxIndex + 2, 1));
sheet.getRange('L28:S').copyTo(sheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
Upvotes: 1
Views: 64
Reputation: 201613
I believe your goal as follows.
L28:S
.sheet.getRange(maxIndex + 2, 1)
. By this, the values are copied to the column "A". I think that this is the reason of your issue.getNextDataCell
might be able to be used.When your script is modified, it becomes as follows.
function Update() {
var sheet = SpreadsheetApp.getActiveSheet();
// I modified below script.
var range = sheet.getRange("U1:U" + sheet.getLastRow());
var temp = range.getNextDataCell(SpreadsheetApp.Direction.DOWN);
var destRange = temp.getRow() == sheet.getMaxRows() && sheet.getRange("U1").isBlank() ? sheet.getRange("U1") : temp.offset(1, 0);
// destRange.activate(); // When you use this line, the start of copy is activated.
sheet.getRange('L28:S').copyTo(destRange, SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
Upvotes: 2