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 does not respect the if condition and always returns the last row of the array.
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").getDisplayValue();
for (var i = 0; i < data.length; i++){
if (data[i][0] == date) {
break;
}
var oldinflow = data[i][1];
var oldoutflow = data[i][2];
}
formSS.getRange("H8").setValue(oldinflow);
formSS.getRange("H11").setValue(oldoutflow);
}