I'm working with Google Sheets Script Editor and I'm trying to do a check to see if a cell contains the text DROPPED, DENIED, WEBSITE, POTENTIAL, SELECTED, TESTING, INACTIVE, or ACTIVE. If it contains DROPPED or DENIED, I need it to say "DENIED", if it says SELECTED/TESTING/INACTIVE/ACTIVE, it needs to say "ACCEPTED", and if it says WEBSITE/POTENTIAL it needs to say "INCOMPLETE".
My code looks roughly like this. I don't have any formal training so it's probably a mess, but hopefully there's an easier way to do it.
if (('' + data1[i][1]).trim().toUpperCase() == "DROPPED" ||
('' + data1[i][1]).trim().toUpperCase() == "DENIED") {
sh2.getRange(j + 1, 11, 1, 1).setValue("DENIED");
}else if (('' + data1[i][1]).trim().toUpperCase() == "SELECTED" ||
('' + data1[i][1]).trim().toUpperCase() == "TESTING" ||
('' + data1[i][1].trim().toUpperCase() == "INACTIVE" ||
('' + data1[i][1].trim().toUpperCase() == "INACTIVE" ||
('' + data1[i][1].trim().toUpperCase() == "ACTIVE") {
sh2.getRange(j + 1, 11, 1, 1).setValue("ACCEPTED");
}else if (('' + data1[i][1]).trim().toUpperCase() == "WEBSITE" ||
('' + data1[i][1]).trim().toUpperCase() == "POTENTIAL") {
sh2.getRange(j + 1, 11, 1, 1).setValue("INCOMPLETE");
I'm pulling this from a "Cross Check" script that's comparing cell contents between two different sheets, which is why it's using sh2.getRange
. Mostly I'm just wondering if there's an easier way to write it than that huge if/elseif
. If not, that's fine, it's just going to need to run a couple thousand checks so if I can do it in a way that minimizes the amount of legwork the script does, that would be better.
The only thing I can think of is just forcing the cell to be upper case before it does the checks, and then putting it back to proper case when the checks are done. I don't know if continuing to do toUpperCase
is going to take more time or not. Honestly I don't know entirely how that even works, I just know it does. We contracted out the original script and I don't know exactly what he did, he didn't comment anything so I had to figure it out myself.