-
-
Save palumbo/e47839bcdb7a484d50a7c6e36c861928 to your computer and use it in GitHub Desktop.
function onOpen(e) { | |
let ui = SpreadsheetApp.getUi(); | |
ui.createMenu('🤖 Automation Tools') | |
.addItem('Move reps to individual sheets', 'moveRows') | |
.addToUi(); | |
}; | |
function moveRows() { | |
const ss = SpreadsheetApp.getActiveSpreadsheet(); | |
const sheet = ss.getActiveSheet(); | |
const eddieSheet = SpreadsheetApp.openById('1wvrKeJd2zj3_tT1W0jkXoIZEbGf4_-0SSSesRgtK_Og').getSheetByName('Sheet1'); | |
const eddieLastRow = eddieSheet.getLastRow(); | |
const josephSheet = SpreadsheetApp.openById('1U0xTv-0_dyFsF3AwwDzT86cjqySjnJcZkn4d4n0MZ1k').getSheetByName('Sheet1'); | |
const josephLastRow = josephSheet.getLastRow(); | |
let lastRow = sheet.getLastRow(); | |
let sortRange = sheet.getSheetValues(2,1,lastRow, 4); | |
Logger.log(lastRow) | |
// Logger.log(typeof(sortRange)) | |
// Logger.log(sortRange.length); | |
let josephCounter = 1; | |
let eddieCounter = 1; | |
for (var i = 1; i <= sortRange.length; i++) { | |
let name = sheet.getRange(i,1).getValue(); | |
console.log(i + " - " + name); | |
if (name == "Joseph Palumbo") { | |
let rowValues = sheet.getRange(i, 1, 1, 4).getValues(); | |
josephSheet.getRange(josephLastRow+josephCounter, 1, 1, 4).setValues(rowValues); | |
josephCounter++; | |
} | |
if (name == "Eddie Jauregui") { | |
let rowValues = sheet.getRange(i, 1, 1, 4).getValues(); | |
eddieSheet.getRange(eddieLastRow+eddieCounter, 1, 1, 4).setValues(rowValues); | |
eddieCounter++; | |
} | |
}; | |
}; | |
@boudiccamorgana Think of the ranges like lego blocks. You can cut up the first sheet any way you want by defining different ranges that you want to copy, then you can put them wherever you want on the target sheet, combining the disparate ranges into one table.
Okay, so what does that look like in code? I'm trying to figure out how I would separate the blocks on the code - so I can have my ranges with
let sortRange = sheet.getSheetValues(2,1,lastRow, 7);
let otherRange = sheet.getSheetValues(9,1,lastRow, 6);
but I'm stuck on where to put the code to tell it where to paste?
I am totally new to writing scripts, so thanks in advance for your patience. When I try to run this script on my master sheet, I get "TypeError: Cannot read properties of null (reading 'getLastRow')"
Any advice? Thank you!
Sorry I am extremely new to this so I just want to clarify: like to run the script twice with two ranges, or to somehow say get(rangex and rangey) so to speak ? Idk if this helps or makes it worse but the new sheets don’t skip that column so the master sheet’s “I” would be the new one’s “h” and move it in a row.