Moses
Moses

Reputation: 236

Google Apps Script with multiple IF conditions

I use this formula in Column G

=IF(ISBLANK(A3),"User missing",IFS(C3=E3,0,E3="","Empty Data",C3<>E3,"Wrong Data"))

Applying this formula for 30k data make my sheet slow. Need to convert to script.

As If and IFS is used in same formula, I am facing difficult to convert this to Script.

Condition:

If Column A is Empty then "User Missing"
If A have data, 
then condition is
If E is empty then "Empty Data"
If C and E is not equal then "Wrong Data"
If C and E is equal then 0

Upvotes: 1

Views: 230

Answers (1)

Marios
Marios

Reputation: 27390

Given that you need the columns A,C,E I used the range A2:E and paste the resulting data in column F:

function myFunction(){
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const sh = ss.getSheetByName("Sheet1");
    const vals = sh.getRange("A2:E"+sh.getLastRow()).getValues();
    const cvals = []; 
    vals.forEach(r=>{           
         cvals.push( [
                 r[0]==''?"User Missing":
                 r[4]==''?"Empty Data":
                 r[2]!=r[4]?"Wrong Data":0
         ])            
      });
    sh.getRange(2,6,cvals.length,1).setValues(cvals); // paste in column F
}

Upvotes: 3

Related Questions