EXCEL将新列添加到嵌套的if语句中

时间:2017-01-24 20:13:20

标签: excel if-statement excel-formula vlookup nested-if

=IF(
Payment_Rules = Save_Only,
IF(
    VLOOKUP(
        F7 & $B$13,
        $Y$13:$AC$429,
        IF(
            $Z$11 = $B$6,
            2,
            IF(
                $B$6 = $AA$11,
                3,
                IF(
                    $B$6 = $AB$11,
                    4,
                    5
                )
            )
        ),
        FALSE
    ) < D6,
    D6,
    VLOOKUP(
        F7 & $B$13,
        $Y$13:$AC$429,
        IF(
            $Z$11 = $B$6,
            2,
            IF(
                $B$6 = $AA$11,
                3,
                IF(
                    $B$6 = $AB$11,
                    4,
                    5
                )
            )
        ),
        FALSE
    )
),
VLOOKUP(
    F7 & $B$13,
    $Y$13:$AC$429,
    IF(
        $Z$11 = $B$6,
        2,
        IF(
            $B$6 = $AA$11,
            3,
            IF(
                $B$6 = $AB$11,
                4,
                5
            )
        )
    ),
    FALSE
)

到目前为止,我已经在我的excel文件中嵌套了if语句并且它工作正常,但是新的列被添加到工作簿中,所以我必须稍微调整这些代码以覆盖新列。(列AC:AF添加)

=IF(
Payment_Rules = Save_Only,
IF(
    VLOOKUP(
        F6 & $B$13,
        $Y$13:$AF$429,
        IF(
            $Z$11 = $B$6,
            2,
            IF(
                $B$6 = $AA$11,
                3,
                IF(
                    $B$6 = $AB$11,
                    4,
                    IF(
                        $B$6 = $AC$11,
                        5,
                        IF(
                            $B$6 = $AD$11,
                            6,
                            IF(
                                $B$6 = $AE$11,
                                7,
                                IF(
                                    $B$6 = $AF$11,
                                    8
                                )
                            )
                        )
                    )
                )
            )
        ),
        FALSE
    ) < D5,
    D5,
    VLOOKUP(
        F6 & $B$13,
        $Y$13:$AF$429,
        IF(
            $Z$11 = $B$6,
            2,
            IF(
                $B$6 = $AA$11,
                3,
                IF(
                    $B$6 = $AB$11,
                    4,
                    IF(
                        $B$6 = $AC$11,
                        5,
                        IF(
                            $B$6 = $AD$11,
                            6,
                            IF(
                                $B$6 = $AE$11,
                                7,
                                IF(
                                    $B$6 = $AF$11,
                                    8
                                )
                            )
                        )
                    )
                )
            )
        ),
        FALSE
    )
),
VLOOKUP(
    F6 & $B$13,
    $Y$13:$AC$429,
    IF(
        $Z$11 = $B$6,
        2,
        IF(
            $B$6 = $AA$11,
            3,
            IF(
                $B$6 = $AB$11,
                4,
                IF(
                    $B$6 = $AC$11,
                    5,
                    IF(
                        $B$6 = $AD$11,
                        6,
                        IF(
                            $B$6 = $AE$11,
                            7,
                            IF(
                                $B$6 = $AF$11,
                                8
                            )
                        )
                    )
                )
            )
        )
    ),
    FALSE
)

这是我的新代码所得到的,但它给了我#REF!错误。我无法弄清楚出了什么问题。由于原始代码工作正常,我知道调用引用没有任何问题。我该如何解决这个错误?

谢谢!

1 个答案:

答案 0 :(得分:0)

将VLOOKUP中的所有IF()更改为MATCH:

=MATCH($B$6,$Y$11:$DD$11,0)

除非您的列多于DD,否则不需要更新。

=IF(Payment_Rules=Save_Only,IF(VLOOKUP(F7&$B$13,$Y$13:$DD$429,
MATCH($B$6,$Y$11:$DD$11,0),FALSE)<D6,D6,VLOOKUP(F7&$B$13,$Y$13:$DD$429,
MATCH($B$6,$Y$11:$DD$11,0),FALSE)),VLOOKUP(F7&$B$13,$Y$13:$DD$429,
MATCH($B$6,$Y$11:$DD$11,0),FALSE))