Reputation: 11091
When I select a row in the Edit
menu of Google Sheet in web browser there is a nice functionality Move line up
and Move line down
.
The problem comes when I need to move a line 10 lines up or down: I need to open the menu a lot of times...
Is it possible to assign a keyboard shortcut? I would greatly simplify the things.
Upvotes: 1
Views: 2149
Reputation: 11091
There is another way to move 1 row up/down for X positions in one iteration in Google Sheets.
Instead of moving one row X times down we can select X rows below the row we need to move and move them up one time.
Upvotes: 2
Reputation: 3010
Yes, you could assign a keyboard shortcut, which would run a saved macro.
I tested by recording a macro of using the Edit menu to move a row up one line. Then by editing the macro, I could change the "1" to a "10", to move the row up ten lines. The macro looks like this.
function MoveRowUp10Rows() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getActiveSheet().moveRows(spreadsheet.getActiveRange(), spreadsheet.getActiveRange().getRow() - 10);
};
Depending on the nature of your editing work, you could create several, to move a row up 3,5,or 10 rows, or whatever you need, each with a keyboard shortcut.
Or you could enhance the macro to add a pop-up prompt for the number of rows you want to move - up or down. (Search here on SO to find how to add user input to a script/macro...)
Note the above macro works even if you've just selected one cell on a row - no need to select the whole row.
Upvotes: 5