Google script - Not equal to not working correctly?

I'm currently working on a script that will import the holiday and appointments calender to make it public, however there are some things on this holiday calendar that need removing so after the sheets are imported i'm scanning the values of each cell to remove the cells that contain stuff others shouldnt be able to see

var code = ss.getSheetByName(mysheet).getRange(k,j).getValue();
if (code != "HD" || code != "H" || code != "BH" || code !== "") { ss.getSheetByName(mysheet).getRange(k,j).setValue("");
}

This is the code that is used for getting the value of the cell and checking it, it looks for cells that are not blank or do not contain any off the allowed codes however for some reason it keeps picking up every blank cell, why is this?

Also is there any over way to make this code run more faster and effectively?

function scanSheet(mysheet,lastdatecol){ var lastrw= ss.getSheetByName(mysheet).getDataRange().getLastRow(); for (var k=3; k<=lastrw; k++){ var surname = holidayNamesObjects[k-3].surname; var forename = holidayNamesObjects[k-3].firstName; ss.getSheetByName(mysheet).getRange(k, 1).setValue(forename + " " + surname) for (var j = 3; j < lastdatecol+1; j++){ var code = ss.getSheetByName(mysheet).getRange(k,j).getValue(); if (code != "HD" || code != "H" || code != "BH" || code !== "") { ss.getSheetByName(mysheet).getRange(k,j).setValue(""); } } }
}

1 Answer

code !== "" needs to be code != "" Using && code instead may work better

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like