I have a spreadsheet with a header. In column P, I have a column of percentages. Anything over 150%, I want to move that entire row over to a new worksheet called "Groups".
I don't have much code right now because I tried about 5 different ways and wound up deleting my work. :/
CodePudding user response:
If you want to copy the information from the columns to another spreadsheet you can try this:
function copyToSheet() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var rows = sourceSheet.getDataRange().getValues();
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
for(var i=0; i< rows.length; i )
{
if(rows[i][2]>150)
{
targetSheet.appendRow(rows[i]);
}
}
}
The script takes the information from the source sheet and then compares the data from column C for each row and if the value is higher than 150 it copies the whole row to a different sheet.
This is my sample data in Sheet1:
Here is the result in Sheet2 after running the script:
You can adapt the script depending of your needs.
CodePudding user response:
If you have some AppScript experience, this may help:
sort range by percent column descending;
find first row with percent below 150%;
Get values from range rows 2 to that row minus 1;
Delete rows 2 through that row minus 1;
set values to other tab with range starting at getLastRow()