I have some relatively simple code below that throws an error: : "Cannot convert NaN to (class)".
All I want to do is copy some cells from one place to another!
Can anyone please let me know what is wrong with this code?
Many thanks in advance.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet 1');
var values = sheet.getDataRange().getValues()
for( var row = values.length -1; row >= 0; --row )
if (values[row][5] == 'Here')
var maxRows = sheet.getMaxRows()
var startRow = (row)+1
var numRows = (maxRows)-(row)
var Range = sheet.getRange(startRow, 3, numRows, 3).getValues()
sheet.getRange(row, 3, numRows, 3).setValues(Range) // (row, column, numRows, numColumns)
}
So as the code hopefully shows, I want to copy cells in the range C:E but only rows x to getMaxRows(), where x is the row number where 'Here' is found in column F, plus 1. Then I want to paste this into the same columns C:E but one row higher than originally (into the same row as 'Here' in column F).
Any help would be very much appreciated. Thanks for looking.
EDIT: The error is on this line :
var Range = sheet.getRange(startRow, 3, numRows, 3).getValues()
In my sheet, the cells to be copied could countain blank cells and even entire blank rows. Could this be causing the issue?
newRangein there? because that variable is never defined. Also, does it give you a line number that is throwing that error? - Phil Bozak