简体   繁体   English

如何做一个if语句

[英]How to do an if statement

This question is linked to Formula to remove every middle name in a cell in Excel .这个问题链接到Formula to remove every middle name in a cell in Excel

I basically want to make an if else statement in excel. So the IF checks if the cell is equal to "Gian" OR "Pier", if the condition is confirmed the formula proceeds to use this other formula我基本上想在 excel 中做一个 if else 语句。所以IF检查单元格是否等于“Gian”“Pier”,如果条件得到确认,公式将继续使用这个其他公式

=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2)

Sorry guys idk how to do it in an excel way.对不起,伙计们,我不知道如何以 excel 的方式做到这一点。 I can show you in for example in a Java or C way.例如,我可以以 Java 或 C 的方式向您展示。

if(A2=="Pier" || A2=="Gian")
       =IFERROR(LEFT(A2,FIND(" ",A2)-1),A2) \\the excel formula that deletes every second/third name if the cell

在此处输入图像描述

if formula in excel that checks a condition and if its verified it proceeds to use another excel formula如果 excel 中的公式检查一个条件,如果它得到验证,它会继续使用另一个 excel 公式

You could try the following as per your Excel Versions您可以根据您的 Excel 版本尝试以下操作

在此处输入图像描述


• Formula used in cell B2 • 单元格B2中使用的公式

=IF(OR(TEXTBEFORE(A2&" "," ")={"Pier","Gian"}),A2,TEXTBEFORE(A2&" "," "))

Or, in cell C2或者,在单元格C2

=IF(OR(LEFT(A2&" ",FIND(" ",A2&" ")-1)={"Pier","Gian"}),A2,LEFT(A2&" ",FIND(" ",A2&" ")-1))

Just adding the use of LET() which makes it simpler,只需添加LET()的使用就可以使它更简单,

在此处输入图像描述


• Formula used in cell B2 • 单元格B2中使用的公式

=LET(x,TEXTBEFORE(A2&" "," "),IF(OR(x={"Pier","Gian"}),A2,x))

Or, Formula used in cell C2或者,单元格C2中使用的公式

=LET(x,LEFT(A2&" ",FIND(" ",A2&" ")-1),IF(OR(x={"Pier","Gian"}),A2,x))

Using MAP() to Spill as one dynamic array formula but the logic remains same.使用MAP()将 Spill 作为一个动态数组公式使用,但逻辑保持不变。

在此处输入图像描述


• Formula used in cell D2 • 单元格D2中使用的公式

=MAP(A2:A6,LAMBDA(m,
LET(x,TEXTBEFORE(m&" "," "),
IF(OR(x={"Pier","Gian"}),m,x))))

you have to use the AND(...) and OR(..) for chaining logical conditions.您必须使用AND(...)OR(..)来链接逻辑条件。

Here's an example 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM