I am working on a function that would
- Go row by row through a specified column in a Google sheet (column H indicated as value[7] in the script).
- Based on the cell in the value[7] column having specific value ("YES") it would select the entire row.
- It would then copy the selected row (in its entirety) into a separate sheet within the same document.
This is what I've got so far:
function moveRowsBasedOnCellValue(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var master = ss.getSheetByName('Main');
var values = master.getDataRange().getValues(); //selects all values in a sheet
values.forEach(function(value){
//if cell in the column H equals YES execute the script
if (value[7] == "YES"){
//variable to select all columns in the source sheet that aren't blank
var colWidth = master.getMaxColumns();
//variable containing the target sheet
var destinationYeses = ss.getSheetByName("Yeses");
//select first empty row in the destination sheet
var destinationYesesRange = destinationYeses.getRange(destinationYeses.getLastRow()+1,1);
//copy the relevant row into the sheet
master.getRange(value,1, 1, colWidth).copyTo(destinationYesesRange);
}});
}
The script executes fine until the last row of the script:
master.getRange(value,1, 1, colWidth).copyTo(destinationYesesRange);
The error states:
Cannot convert [here the Logger error provides a list of all values in a row separated by a comma] to (class).
Any thoughts on what I may be doing wrong?