简体   繁体   English

删除 Excel 单元格中每个中间名的公式

[英]Formula to remove every middle name in a cell in Excel

Heello, I'm trying to remove every second and/or third name of every person in my excel file.你好,我正在尝试删除我的 excel 文件中每个人的第二个和/或第三个名字。 Now i'm doing it manually (and it' s very boring).现在我手动做(这很无聊)。 Is there any formula to to it automatically?有什么公式可以自动生成吗?

For example I have cell A1 that contains "Filippo Luigi Carlo", is possible to convert it to only "Filippo"?例如,我的单元格 A1 包含“Filippo Luigi Carlo”,是否可以将其转换为仅“Filippo”?

deleting every second and third(if the person has it) name in every cell of an excell file在 excel 文件的每个单元格中删除第二个和第三个(如果有人有的话)名字

How about:怎么样:

=left(A1,find(" ",A1,1)-1)

I assumed that the first name is in cell A1, alter if not.我假设名字在单元格 A1 中,如果不是则更改。

Based on your comment about "pier" then:根据您对“码头”的评论,然后:

IF(IFERROR(FIND("pier",LEFT(A1,4),1),0)=1,A1,LEFT(A1,FIND(" ",A1,1)-1))

在此处输入图像描述

You will want to use the following:您将需要使用以下内容:

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

What does it do?它有什么作用?

  1. Finds the first space in your target text FIND(" ", A1)查找目标文本中的第一个空格FIND(" ", A1)
  2. Takes all the characters from the start of your target text up until the spot before the first space LEFT(A1, {step 1} - 1)获取从目标文本开始到第一个空格之前的所有字符LEFT(A1, {step 1} - 1)
  3. If there is an error (for example there is no space in your target text), it will simply return the original target text =IFERROR({step 2}, A1)如果出现错误(例如目标文本中没有空格),它将简单地返回原始目标文本=IFERROR({step 2}, A1)

Limitations:限制:

  • The first name cannot include a space (example: Anne Marie Jones will return Anne instead of Anne Marie )名字不能包含空格(例如: Anne Marie Jones将返回Anne而不是Anne Marie
  • Any other errors will simply return the original target text任何其他错误只会返回原始目标文本

joining the party, I assume you want to keep the first name and the last name.加入聚会,我假设你想保留名字和姓氏。 The first name is given by @solar-Mike above.名字由上面的@solar-Mike 给出。 For the last name, unfortunately excel only has formulae that search or find left to right, so more than two names are a problem.对于姓氏,不幸的是 excel 只有从左到右搜索或查找的公式,所以两个以上的名字是个问题。 This site seems to give a good solution: a reverse find function 这个网站似乎给出了一个很好的解决方案:反向查找 function

The formula for the last name is horrendous: =IF( ISERROR( FIND(" ",A1) ),A1,RIGHT(A1, LEN(A1)-FIND("~", SUBSTITUTE(A1," ","~", LEN(A1)-LEN(SUBSTITUTE(A1," ","")) ) ) ) )姓氏的公式很可怕: =IF( ISERROR( FIND(" ",A1) ),A1,RIGHT(A1, LEN(A1)-FIND("~", SUBSTITUTE(A1," ","~" , LEN(A1)-LEN(替换(A1," ","")) ) ) )

Tack on the bit to get the first name, and you get:点击位以获取名字,您将获得:

=left(A1,find(" ",A1,1)-1) & " " & IF( ISERROR( FIND(" ",A1) ),A1,RIGHT(A1, LEN(A1)-FIND("~", SUBSTITUTE(A1," ","~", LEN(A1)-LEN(SUBSTITUTE(A1," ","")) ) ) ) ) =left(A1,find(" ",A1,1)-1) & " " & IF( ISERROR( FIND(" ",A1) ),A1,RIGHT(A1, LEN(A1)-FIND("~" , 替换(A1," ","~", LEN(A1)-LEN(替换(A1," ","")) ) ) )

That will drop all the middle names.这将删除所有中间名。

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

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