I have a google form which returns responses to a google spreadsheet named 'Form responses 1' for which column A is the timestamp (this shows up as '25/06/2015 21:36:00' in the google spreadsheet cell) and column G and I contains numerical values of which I am interested in the last row with not "" values. The last row with not "" values in both columns G and I may not be the exact same row.
1) Is there a way not to redefine "var lastRow = spreadsheet.getSheetByName("Form responses 1").getLastRow();" in line 11? I found that this line is necessary to reset the definition for var lastRow.
Without it, the last row with not "" values in column I would be wrong (it gets the next non "" row after moving on from column G's last row with non "" values instead of counting upwards from the last row of column I).
2) I am getting a NaN for the LastNonZeroDate for both columns G and I for which I am trying to retrieve in milliseconds with the the getTime() function. How can I remedy this?
If I retrieve the value of "new Date('responsesvalues[lastRow - 1][0]')getTime()" in a msg box instead, it gives me "Thu Jun 25 2015 21:35:59 GMT+0800 (HKT)".
Thanks in advance for any help.
// get the data range
var lastRow = spreadsheet.getSheetByName("Form responses 1").getLastRow();
var responsesvalues = spreadsheet.getSheetByName("Form responses 1").getRange("A1:Q" + lastRow).getValues();
// get the last row in column G with non-zero value and corresponding date
for (; responsesvalues[lastRow - 1][6] == "" && lastRow > 0; lastRow--) {}
var GLastNonZero = responsesvalues[lastRow - 1][6];
var GLastNonZeroDate = new Date('responsesvalues[lastRow - 1][0]').getTime();
// get the last row in column I with non-zero value and corresponding date
var lastRow = spreadsheet.getSheetByName("Form responses 1").getLastRow();
for (; responsesvalues[lastRow - 1][8] == "" && lastRow > 0; lastRow--) {}
var ILastNonZero = responsesvalues[lastRow - 1][8];
var ILastNonZeroDate = new Date('responsesvalues[lastRow - 1][0]').getTime();
new Date('responsesvalues[lastRow - 1][0]')Why the quotes? - AndreaslastRowin the loop...; lastRow--). Use an extra variable instead. - Andreas