I have a google sheet that I would like to set up a script for, which looks for specific criteria such as if a cell in a range contains something that is also in another column, or contains something specific. My example sheet shows what I would like to happen: Example sheet & screenshot
Anything in the name column (A) that contains the city name (B) as part of it would get a note ("Are you sure this is right?"). Ie if Row 1 has "Las Vegas Smith" as the name and "Las Vegas" as the city, it would get the note. If Row 5 has "Charlotte Applegate" as the name and "Applegate" as the city, it would also get the note.
I also need to add a note to other cells in particular columns that meet criteria, but they are only looking at one column. Ie anything that contains a hyphen in Column A would get a note like "Hyphen in the name?"
I have been able to highlight the name/city items using conditional formatting, using a custom formula =REGEXMATCH (LOWER($A2),LOWER($B2))
. And just using 'text contains' works for the rest for conditional formatting. But I'd like to also add a note in addition to making them a different color.
I have found something to add notes,
function addNote() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Testing');
var targetCell = sheet.getRange("A2:A5");
var sourceCell = sheet.getRange("E2:E3");
var noteText = sourceCell.getValue();
targetCell.setNote(noteText);
}
(pointing to the second tab, Testing, which is just a copy of the first w/formatting removed.) This results in the text from E2 as a note to every cell in the A2:A5 range. I'm unsure how to add in that it needs to look for criteria and add the appropriate note based on that, and additionally that it needs to look for cells that contain that, not that match it exactly.