Move Rows With Different Tab Names – Dropdown

How to move rows between tabs where the dropdown options and the tab names don’t match.
Important notes:
* The indices of the 2 arrays must match, else the data will transfer improperly.
* Since this is an onEdit script it is not meant to be run manually. Doing so will cause failure.

Sheet (to copy from File then “Make a copy”):
https://docs.google.com/spreadsheets/…

Script:
function onEdit(e){
let r = e.range;
if (r.columnStart != 3 || r.rowStart == 1 || e.value == null) return;
const sh = SpreadsheetApp.getActive();
const valArray = [“Commander”,”Captain”,”ARC”,”Commando”];
const destArray = [“Cody”,”Rex”,”Echo”,”Sev”];
let dest = sh.getSheetByName(destArray[valArray.indexOf(e.value)]);
let src = sh.getActiveSheet();
if (dest.getName() == src.getName()) return;
src.getRange(r.rowStart,1,1,3).moveTo(dest.getRange(dest.getLastRow()+1,1,1,3));
src.deleteRow(r.rowStart);
}

Leave a Reply

Your email address will not be published. Required fields are marked *