Recently I worked on an example for someone that wanted to know how to move ranges around on a Google Spreadsheet. And what I came up with is a small function that will move the active or selected range in any direction any number of rows and columns. So it's a fairly versatile little routine that could be adapted to several situations.
function rangeJog(hoffset,voffset,moveselection)
{
var hoffset = (typeof(hoffset) !== 'undefined')? hoffset : 1;
var voffset = (typeof(voffset) !== 'undefined')? voffset : 0;
var moveselection = (typeof(moveselection) != 'undefined')? moveselection : true;
var src = SpreadsheetApp.getActiveRange();
var srcA1 = src.getA1Notation();
var row = src.getRow() + voffset;
var col = src.getColumn() + hoffset;
var rows = src.getLastRow() - src.getRow() + 1;
var cols = src.getLastColumn() - src.getColumn() +1;
if((row<1) || (col<1))
{
dispStatus('No More Room to Move','<p>Destination Row is ' + row + '.<br />Destination Column is ' + col + '.<br />No more room to move in chosen direction.<br /><input type="button" value="exit" onClick="google.script.host.close();" /></p>', 400, 200);
//SpreadsheetApp.getUi().alert('No more room to move.');
}
else
{
var des = SpreadsheetApp.getActiveSheet().getRange(src.getRow() + voffset, src.getColumn() + hoffset, src.getLastRow() - src.getRow() + 1, src.getLastColumn() - src.getColumn() +1);
var srcA = src.getValues();
src.clearContent();
des.setValues(srcA);
if(moveselection)
{
SpreadsheetApp.getActiveSheet().setActiveSelection(des);
}
}
var end = "is near";
}