Google表格/ Excel – “如果A,则B,如果D,则E”匹配

在Google表格或Excel中,是否有一种简单的方法可以根据另一个单元格的几个可能值之一将值插入到单元格中?

换一种说法,

  • 如果A1包含“红色”,那么B1应填写“危险”
  • 如果A1包含“蓝色”,则B1应填写“正常”
  • 如果A1包含“绿色”,那么B1应填写“继续”

写这种匹配的语法是什么?

提前致谢!

B1中input:

 =LOOKUP(A1,{"blue","green","red"},{"normal","proceed","hazard"}) 

在这里输入图像说明

请注意,查找值必须按字母顺序排列。

使用B1中的下面一行来获得答案。 确保在A1中find正确的拼写,否则如果A1为空或拼写错误,您将看到FALSE。

 =IF(A1="red","Hazard",IF(A1="blue","normal",IF(A1="green","proceed"))) 

这是基于单元格颜色的不同方法

选项显式

 Public Function ColorIndexes(Rango As Range) As Variant Application.Volatile If Rango.Interior.ColorIndex = 3 Then ColorIndexes = "Hazzard" ElseIf Rango.Interior.ColorIndex = 24 Or Rango.Interior.ColorIndex = 37 Or Rango.Interior.ColorIndex = 23 Or Rango.Interior.ColorIndex = 49 Then ColorIndexes = "Normal" ElseIf Rango.Interior.ColorIndex = 50 Or Rango.Interior.ColorIndex = 35 Or Rango.Interior.ColorIndex = 48 Or Rango.Interior.ColorIndex = 12 Or Rango.Interior.ColorIndex = 56 Or Rango.Interior.ColorIndex = 14 Then ColorIndexes = "Proceed" Else ColorIndexes = "Not matched" End If End Function