Skip to content Skip to sidebar Skip to footer

Identify Specific Row Based On Date

What this code does is to identify the row of the array based on the input (Date) and return the values associated with the input date. However, this for loop is not working as it

Solution 1:

You need to get the valueOf() of the date object instead.

Try this:

function viewData() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var formSS = ss.getSheetByName("Overall Cashflow"); //Data entry Sheet
  var datasheet = ss.getSheetByName("Cashflow Tracker Data"); //Data Sheet
  var data = datasheet.getDataRange().getValues();
  var date = formSS.getRange("H5").getValue().valueOf();
  
  for (var i = 0; i < data.length; i++){ 
        if (data[i][0].valueOf() == date) {
           break; 
        }
        var oldinflow = data[i][1];
        var oldoutflow = data[i][2]; 
  }
  

  formSS.getRange("H8").setValue(oldinflow);
  formSS.getRange("H11").setValue(oldoutflow);
}

Solution 2:

getValues() might return Date object for cells holding "dates", by the other hand getDisplayValue() will return a string. This might explain why (data[i][0] == date is no working.

To prevent on quick and dirty solution that might be good enough is instead of using getValues(), to use getDisplayValues().


Post a Comment for "Identify Specific Row Based On Date"