嵌套IF,AND,OR函数比较并给出结果excel

时间:2017-06-30 12:00:26

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

需要此功能的帮助。

=IF(AND($F5="Miks M",OR($G5="Miks M")),0,IF(AND($F5="Miks M",OR($G5="Miks L")),1,IF(AND($F5="Miks M",OR($G5="Miks XL")),2,IF(AND($F5="Miks M",OR($G5="Miks S")),-1,IF(AND($F5="Miks M",OR($G5="Miks XL PLUS")),3,IF(AND($F5="Miks M",OR($G5="Miks XXL")),4,IF(AND($F5="Miks M",OR($G5="Super")),5,IF(AND($F5="Miks M",OR($G5="Prica Plus")),-2,IF(AND($F5="Miks S",OR($G5="Prica Plus")),-1,IF(AND($F5="Miks S",OR($G5="Miks S")),0,IF(AND($F5="Miks S",OR($G5="Miks M")),1,IF(AND($F5="Miks S",OR($G5="Miks L")),2,IF(AND($F5="Miks S",OR($G5="Miks XL")),3,IF(AND($F5="Miks S",OR($G5="Miks XL PLUS")),4,IF(AND($F5="Miks S",OR($G5="Miks XXL")),5,IF(AND($F5="Prica Plus",OR($G5="Prica Plus")),0,IF(AND($F5="Prica Plus",OR($G5="Miks S")),1,IF(AND($F5="Prica Plus",OR($G5="Miks M")),2,IF(AND($F5="Prica Plus",OR($G5="Miks L")),3,IF(AND($F5="Prica Plus",OR($G5="Miks XL")),4,IF(AND($F5="Prica Plus",OR($G5="Miks XL PLUS")),5,IF(AND($F5="Prica Plus",OR($G5="Miks XXL")),6,IF(AND($F5="Miks L",OR($G5="Prica plus")),-3,IF(AND($F5="Miks L",OR($G5="Miks S")),-2,IF(AND($F5="Miks L",OR($G5="Miks M")),-1,IF(AND($F5="Miks L",OR($G5="Miks L")),0,IF(AND($F5="Miks L",OR($G5="Miks XL")),1,IF(AND($F5="Miks L",OR($G5="Miks XL PLUS")),2,IF(AND($F5="Miks L",OR($G5="Miks XXL")),3,IF(AND($F5="Miks L",OR($G5="Super")),4,IF(AND($F5="Miks XL",OR($G5="Prica plus")),-4,IF(AND($F5="Miks XL",OR($G5="Miks S")),-3,IF(AND($F5="Miks XL",OR($G5="Miks M")),-2,IF(AND($F5="Miks XL",OR($G5="Miks L")),-1,IF(AND($F5="Miks XL",OR($G5="Miks XL")),0,IF(AND($F5="Miks XL",OR($G5="Miks XL PLUS")),1,IF(AND($F5="Miks XL",OR($G5="Miks XXL")),2,IF(AND($F5="Miks xL",OR($G5="Super")),3,IF(AND($F5="Miks XL Plus",OR($G5="Prica plus")),-5,IF(AND($F5="Miks XL Plus",OR($G5="Miks S")),-4,IF(AND($F5="Miks XL Plus",OR($G5="Miks M")),-3,IF(AND($F5="Miks XL Plus",OR($G5="Miks L")),-2,IF(AND($F5="Miks XL Plus",OR($G5="Miks XL")),-1,IF(AND($F5="Miks XL Plus",OR($G5="Miks XL PLUS")),0,IF(AND($F5="Miks XL Plus",OR($G5="Miks XXL")),1,IF(AND($F5="Miks xL Plus",OR($G5="Super")),2,IF(AND($F5="Miks XXL",OR($G5="Prica plus")),-6,IF(AND($F5="Miks XXL",OR($G5="Miks S")),-5,IF(AND($F5="Miks XXL",OR($G5="Miks M")),-4,IF(AND($F5="Miks XXL",OR($G5="Miks L")),-3,IF(AND($F5="Miks XXL",OR($G5="Miks XL")),-2,IF(AND($F5="Miks XXL",OR($G5="Miks XL PLUS")),-1,IF(AND($F5="Miks XXL",OR($G5="Miks XXL")),0,IF(AND($F5="Miks xXL",OR($G5="Super")),1,IF(AND($F5="Super",OR($G5="Prica plus")),-7,IF(AND($F5="Super",OR($G5="Miks S")),-6,IF(AND($F5="Super",OR($G5="Miks M")),-5,IF(AND($F5="Super",OR($G5="Miks L")),-4,IF(AND($F5="Super",OR($G5="Miks XL")),-3,IF(AND($F5="Super",OR($G5="Miks XL PLUS")),-2,IF(AND($F5="Super",OR($G5="Miks XXL")),-1,IF(AND($F5="Super",OR($G5="Super")),0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

这个功能是否有可能变得更短更简单? 目前它的工作完美但如果它可以更短,那就更好了。 如果单元格F5是Miks M而单元格G5是Miks M则在H5中写入0如果G5是Miks L则在H5中写入1并且打开。

3 个答案:

答案 0 :(得分:3)

创建一个包含您的值的表格,如下所示:

enter image description here

然后一个简单的SUMIFS公式将为您完成剩下的工作:

=SUMIFS($C$1:$C$4,$A$1:$A$4,$F5,$B$1:$B$4,$G5)

另一种可能的解决方案:

如果你只是想看看大小是如何不同的,你可以创建一个更简单的有序表,如下所示:

Prica Plus
S
M
L
XL
XL PLUS
XXL
Super

使用这样的公式:

=MATCH(SUBSTITUTE($G5,"Miks ",""),$A$1:$A$8,0)-MATCH(SUBSTITUTE($F5,"Miks ",""),$A$1:$A$8,0)

上表位于A1:A8。这个公式删除了" Miks"从价值观来看,它只是比较尺寸。更具体地说,它返回表中两种尺寸的位置差异。

答案 1 :(得分:0)

这看起来像是一场噩梦...... 无论如何,如果您可以使用VBA,请尝试将整个公式重写为以下内容:

Option Explicit

Public Function TryMe() As String

    Select Case True
        Case Range("F5") = "Miks M" Or Range("G5") = "Miks M"
            TryMe = "MiksM"
        Case Range("F5") = "MiksL" Or Range("G5") = "MiksL"
            TryMe = "MiksL"
        Case Else
            TryMe = "Something Else"
    End Select

End Function

然后你只会写=TryMe而你会得到结果。

答案 2 :(得分:0)

试试这个公式

=MATCH(G5,{"Prica Plus","Miks S","Miks M","Miks L","Miks XL","Miks XL Plus","Miks XXL","Super"},0)-MATCH(F5,{"Prica Plus","Miks S","Miks M","Miks L","Miks XL","Miks XL Plus","Miks XXL","Super"},0)

以上公式可分为两部分。首先,将Cell G5与您的值匹配

=MATCH(G5,{"Prica Plus","Miks S","Miks M","Miks L","Miks XL","Miks XL Plus","Miks XXL","Super"},0)

其次,将Cell H5与您的值匹配

=MATCH(F5,{"Prica Plus","Miks S","Miks M","Miks L","Miks XL","Miks XL Plus","Miks XXL","Super"},0)

然后减去两个值。