1

I use LibreOffice to create xlsx files. There are some formulas to test conditions. Everything is ok under LibreOffice but when I open the file with Google Sheets formulas give the wrong result.

e.g. the following formula

=IF(C32="","",IF(COUNTIF(C6:C28,"SA|PA|MA|PB|MB")=C32,"0",COUNTIF(C6:C28,"SA|PA|MA|PB|MB")-C32))

gives activates the second COUNTIF as if was an error.

Some explanations:
C32 = 5
C6:C28 contains 5 of the required pars (SA|PA|....)

So I expect the value of 0 but I receive a -5 result. Hope I was clear.

1
  • only regex formulas are able to comprehend | as OR
    – user0
    Jul 3, 2019 at 17:54

1 Answer 1

1

=ARRAYFORMULA(IF(LEN(C32), 
 IF(SUM(N(REGEXMATCH(C6:C28, "SA|PA|MA|PB|MB")))=C32, "0",
    SUM(N(REGEXMATCH(C6:C28, "SA|PA|MA|PB|MB")))-C32), ))

0


alternatives:

=IF(C32<>"", IF(COUNTIF(C6:C28, "SA")+
                COUNTIF(C6:C28, "PA")+ 
                COUNTIF(C6:C28, "MA")+ 
                COUNTIF(C6:C28, "PB")+ 
                COUNTIF(C6:C28, "MB")=5, 0, COUNTIF(C6:C28, "SA")+
                                            COUNTIF(C6:C28, "PA")+ 
                                            COUNTIF(C6:C28, "MA")+ 
                                            COUNTIF(C6:C28, "PB")+ 
                                            COUNTIF(C6:C28, "MB")-C32), )

=ARRAYFORMULA(IF(LEN(C32), 
 IF(SUM(COUNTIF(C6:C28, {"SA"; "PA"; "MA"; "PB"; "MB"}))=5, 0, 
    SUM(COUNTIF(C6:C28, {"SA"; "PA"; "MA"; "PB"; "MB"}))-C32), ))

1
  • 1
    It works. Thank you. First solution is elegant Jul 3, 2019 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.