I have this code that works to find the word “Yes” and replace it with a 1. How do I also add in a line for it to find “No” and replace it with a 0?
function fandr() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var s=ss.getActiveSheet();
var r=s.getDataRange();
var vlst=r.getValues();
var i,j,a,find,repl;
find="Yes"
repl="1"
for (i in vlst) {
for (j in vlst[i]) {
a=vlst[i][j];
if (a==find) vlst[i][j]=repl;
}
}
r.setValues(vlst);
}
Best Answer
I'll do you one better!
It's always best to write code in such away that the behavior can be changed in the future. This has been rewritten such that it can find and replace anything and everything you tell it to by passing in an object as the parameter.
You would call it using
Alright, alright, I get it, that's not exactly what you were asking. The answer to your question is simple, use the "else if" statement