Forum Discussion

lev1954's avatar
lev1954
Copper Contributor
Sep 18, 2024

Using a function in COUNTIF criteria

Is it possible to use a function inside COUNTIF criteria so that it is applied to each cell in the range under test? For instance, I have column A of text values and want to count cells in it with the text longer than 8. I'm trying to write something like =COUNTIF(A:A,LEN(A1)&">8"), but it doesn't work. What is a correct syntax if possible?

  • lev1954 

    If you're looking to obtain a count of all cells with LEN > 8, I'd arrange it like this:

     

    =SUM(N(LEN(A1:A10)>8))

    The LEN portion of the formula returns TRUE or FALSE, N converts those to 1s and 0s, SUM adds them.

  • Patrick2788's avatar
    Patrick2788
    Silver Contributor

    lev1954 

    If you're looking to obtain a count of all cells with LEN > 8, I'd arrange it like this:

     

    =SUM(N(LEN(A1:A10)>8))

    The LEN portion of the formula returns TRUE or FALSE, N converts those to 1s and 0s, SUM adds them.

    • lev1954's avatar
      lev1954
      Copper Contributor
      Thank you a lot, Patrick2788! This workaround works for my specific task and possibly for similar tasks that need to count results of a function applied to each cell in the test range. Good job!

Resources