I'm trying to change this script to search for the date (now) and color the found date in the sheet.
Original script;
function findThis(val) {
var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
var searchStr = "Foo";
Logger.log(res);
var res = findValue(data, searchStr);
if (res != null) {
Browser.msgBox("Found in row " + res[0] + ", column " + res[1]);
}
}
function findValue(data, obj) {
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
if (data[i][j] == obj) {
return [i, j];
}
}
}
return null;
}
My trial and error script;
I think the range is in res but when i want to getRange it does not accept the res coordinates, I've tryed getA1Notation() I am doing it wrong, but stil learning and trying, maybe you can help.
function findThis(val) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // toevoeging
var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
var Today = new Date();
var date = Utilities.formatDate(Today,"GMT+100","dd-M-yyyy");
Logger.log(date)
var searchStr = date;
var res = findValue (data, searchStr);
if (res != null) {
Logger.log(res);
Logger.log(res[0]+", "+res[1]);
var Range = (res[0]+", "+res[1]);
var x = (res[0]+", "+res[1]);
//var C = range.getColumnIndex(res);
var range = Range.getA1Notation()
Logger.log(range);
var value = sheet.getRange([x]).getValue(); //toegevoegd
Logger.log(value);
Logger.log(x);
sheet.getRange(x).setBackgroundColor('Yellow');
Browser.msgBox("Found in row " + res[0] + ", column " + res[1]);
}
}
function findValue(data, obj) {
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
if (data[i][j] == obj) {
return [(i+1), (j+1)];
}
}
}