Search code examples
excelexcel-formulaworksheet-function

Find Length=2 cell in a given range


I have these two rows with an image path. enter image description here In Columns D-H i have only one cell that his length is 2.

I need to find it and do formulas based on it, and I would prefer not writing 5 times "IF", any quick way to find it?


Solution

  • Here's a non-vba, non-CTE/Array formula way to do this:

    =SUMPRODUCT((LEN(D1:H1)=2)*COLUMN(D1:H1)) 
    

    Will spit out the number of the column that has a length of 2. If more than one column fulfills this criteria then you will get back garbage. So don't do that.

    You can pop that into Index() to get the value that was hit:

    =INDEX(A1:H1, 1, SUMPRODUCT((LEN(D1:H1)=2)*COLUMN(D1:H1)))