Using google apps script and spreadsheet, I am trying to do a simple thing, but cannot understand the problem. I have a sheet with an empty column and a column with text. Columns are not next to each other. I am trying to find the text in each cell in one column, and if the text is found, set the cell value in the empty field as βYesβ.
Example (sorry, there is no code - I spent hours with it, but what was so confusing for me is best to give an example):
Column A with text Empty Column F abcd efg hij klmn opq rstu vwxzy Yes
What is the simplest code to find column A for "xyz" and return "Yes" in column F?
I have looked and tried about a dozen different code examples on the Internet and cannot make them work. Appreciate any help with this !!
EDIT (finally hopefully) for my use (I have some helper utilities that get me the column number based on the header name, this code is not included in this, fyi):
var sskey = SpreadsheetApp.openById('**********************') function otherfunction(){ addCustomValue('POCs', 'Groups', 'Champion', 'Champion', 'Yes'); } function addCustomValue(sheetNamestr, searchColnamestr, writeColnamestr, searchKeystr, writeValstr) { var sheet = sskey.getSheetByName(sheetNamestr); var searchColnum = MyUtilities.getColIndexByName(sheet, 1, searchColnamestr); var writeColnum = MyUtilities.getColIndexByName(sheet, 1, writeColnamestr); var data = sheet.getDataRange().getValues(); for (n=0; n<data.length; ++n) { if (data[n][searchColnum-1].toString().match(searchKeystr)==searchKeystr){ data[n][writeColnum-1] = writeValstr}; } sheet.getRange(1,1,data.length,data[0].length).setValues(data); }
Thanks Serge! Now I can run this on my tables based on any columns and conditions!