Created
January 5, 2023 05:55
-
-
Save alecbw/25ecd566995d328ee588428282de72da to your computer and use it in GitHub Desktop.
Largely created by GPT-3; tested in browser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds a menu on user opening the spreadsheet | |
function onOpen() { | |
options = [ | |
{name:"Move Rows", functionName:"moveRows"}, | |
]; | |
SpreadsheetApp.getActiveSpreadsheet().addMenu("~ Tools ~ ", options); | |
} | |
function moveRows() { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var tab = sheet.getActiveSheet(); | |
var range = tab.getActiveRange(); | |
var startRow = range.getRow(); | |
var endRow = range.getLastRow(); | |
var numRows = endRow - startRow + 1; | |
var destinationRow = parseInt(Browser.inputBox("Enter the destination row:")) + 1; | |
var data = range.getValues(); | |
// Insert the data at the destination row, displacing the existing rows | |
tab.insertRows(destinationRow, numRows); | |
tab.getRange(destinationRow, 1, numRows, range.getLastColumn()).setValues(data); | |
// Delete the original rows | |
tab.deleteRows(startRow, numRows); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment