Strange behavior in excel, same formula works for some rows and not for other rows

Kim S 0 Reputation points
2026-11-28T08:59:10.2666667+00:00

Recently Excel is acting weird, I have a simple formula that works only sometime and is simply copied and pasted for multiple rows. The references are correct, but not the results.With the trace

Has anyone else had this issue?

the code is =IF(AND(K7=1,O7=6),"Y1",IF(AND(K7=2,O7=7),"Y2",IF(AND(K7=3,O7=8),"Y3",IF(AND(K7=4,O7=9),"Y4",IF(AND(K7=6,O7=1),"Y6",IF(AND(K7=7,O7=2),"Y7",IF(AND(K7=8,O7=3),"Y8",IF(AND(K7=9,O7=4),"Y9"," "))))))))

Already when through the help (including with a human) and it is claimed the program works right

Thanks

Microsoft 365 and Office | Excel | For home | Windows

2 answers

Sort by: Most helpful
  1. Marcin Policht 114K Reputation points MVP Volunteer Moderator
    2026-11-28T09:25:48.2466667+00:00

    The formula itself is syntactically valid. If it works in some rows but not others, despite the references being correct, I would first investigate the underlying cell values and Excel's calculation settings rather than the formula structure.

    The most common causes are:

    • Numbers stored as text: A cell may display 1 but actually contain the text value "1". In that case, K7=1 evaluates to FALSE. This can happen when data is imported or copied from another application.
    • Hidden decimal values: A cell may display 1 but actually contain 0.999999 or 1.000001. Excel displays the rounded value, but an exact comparison such as K7=1 returns FALSE.
    • Manual calculation mode: Check Formulas → Calculation Options and make sure Automatic is selected. If Excel is in Manual mode, formulas may display outdated results until recalculated.
    • Inconsistent cell contents: Check whether the affected cells contain leading or trailing spaces, formulas returning text, or other unexpected values.

    Start by testing one row that works and one that doesn't. In an empty cell, enter:

    =ISNUMBER(K7)
    

    Then test:

    =K7=1
    

    And:

    =O7=6
    

    These tests will help determine whether Excel is evaluating the underlying values as expected.

    You can also simplify the original formula using IFS:

    =IFS(
    AND(K7=1,O7=6),"Y1",
    AND(K7=2,O7=7),"Y2",
    AND(K7=3,O7=8),"Y3",
    AND(K7=4,O7=9),"Y4",
    AND(K7=6,O7=1),"Y6",
    AND(K7=7,O7=2),"Y7",
    AND(K7=8,O7=3),"Y8",
    AND(K7=9,O7=4),"Y9",
    TRUE," "
    )
    

    However, changing the formula structure is unlikely to fix the problem if the underlying values are inconsistent. I would investigate the data types and actual cell values first.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-11-28T09:00:03.85+00:00

    The formula is structurally valid; test the underlying values in the failing row because Excel compares the stored values and data types—not merely the integers displayed in columns K and O.^1^

    Identify the mismatch

    For a row that displays K=6 and O=1 but does not return Y6, enter these tests in empty cells, replacing 7 with the failing row:

    =K7=6
    =O7=1
    =ISNUMBER(K7)
    =ISNUMBER(O7)
    

    Expected results are four TRUE values. ISNUMBER distinguishes real numbers from text; quoted or text-stored numeric values are not automatically converted by this diagnostic function.^2^

    Then temporarily increase the displayed decimal places for K and O. A cell displaying 6 might actually contain 6.0001, for example. Excel normally compares the complete stored value, even when formatting displays a rounded integer.^1^

    You can also select the failing formula cell and choose Formulas → Evaluate Formula → Evaluate repeatedly. This shows which individual comparison becomes FALSE and can expose text or hidden spaces.^3^

    Apply the matching correction

    If ISNUMBER returns FALSE: the value is text, even if it looks like a number.

    1. Select the affected cells in K or O.
    2. Select the warning indicator, or press Alt+Shift+F10.
    3. Choose Convert to Number.
    4. Fill or recalculate the result formula.

    Microsoft documents text-stored numbers as a cause of unexpected calculation behavior.^4^

    If those columns intentionally contain either numeric text or numbers, coercion can instead be built into the formula:

    =IF(AND(--K7=1,--O7=6),"Y1",
     IF(AND(--K7=2,--O7=7),"Y2",
     IF(AND(--K7=3,--O7=8),"Y3",
     IF(AND(--K7=4,--O7=9),"Y4",
     IF(AND(--K7=6,--O7=1),"Y6",
     IF(AND(--K7=7,--O7=2),"Y7",
     IF(AND(--K7=8,--O7=3),"Y8",
     IF(AND(--K7=9,--O7=4),"Y9",""))))))))
    

    This also replaces " "—one space—with "", a visually empty result.

    If the equality test is FALSE because of hidden decimals: correct the formulas producing K and O, or compare rounded values only if those columns are intended to represent whole numbers:

    =IF(AND(ROUND(K7,0)=6,ROUND(O7,0)=1),"Y6","")
    

    Apply the same rounding pattern to the other conditions. Avoid enabling Set precision as displayed as a quick fix: Microsoft warns that it permanently changes stored values and the original precision cannot be restored.^1^

    If all four tests return TRUE

    Check calculation state:

    1. Select Formulas → Calculation Options → Automatic.
    2. Press Ctrl+Alt+F9 to force recalculation of all formulas in all open workbooks.

    Excel supports Manual calculation mode, in which formula results can remain stale until recalculated.^1^


    References

    1. [Windows](https://support.microsoft.com/excel/change-formula-recalculation-iteration-or-precision-in-excel)
    2. IS functions | Microsoft Support
    3. VALUE is Excel's way of saying, "There's something wrong with the way your formula is typed. Or, there's something wrong with the cells you are referencing." The error is very general, and it can be hard to find the exact cause of it. The information on this page shows common problems and solutions for the error.
    4. Convert numbers stored as text to numbers in Excel | Microsoft Support
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.