As the title says, I do move rows a lot and the lack of default shortcut complicates things for me…
The drag option isn't practical when I need to move some rows to the bottom of a huge sheet!
I tried to us AutoHotKey, but it's a pain since it move one row at a time and takes ages to reach the bottom.
So I'm looking maybe for a JavaScript solution, maybe if someone could put me on the right path with a base example code/references that I could edit/extend later to suit my needs…
Also, any alternative solution I'm not thinking of is welcome.
Edit:
From the title:
- Up: move row(s) one row up
- Down: move row(s) one row down
- Top: move row(s) to the top of the sheet (all the way up)
- End: move row(s) to the bottom of the sheet (all the way down, at the end of non-empty rows)
Best Answer
The following script moves selected consecutive rows in one of four ways described in the question. It is triggered by custom menu items (Custom > Move rows...) which is created by
onOpen
function whenever the spreadsheet is opened. Unfortunately, there is no way to assign keyboard shortcuts to script functions.The structure of functions is simple: insert rows, copy the range (including formulas and formatting), delete old copy of the range. The helper function
getData
eliminates the need to repeat the same data-gathering in each of four functions.