跳到主要内容

在 Excel 中切换名字和姓氏:简单完整的指南

在许多情况下,姓名通常以“名姓”格式列出。然而,在某些情况下,最好将此顺序颠倒为“姓氏,名字”,将姓氏放在前面,然后是逗号,最后是名字。无论是出于组织、数据库管理还是风格原因,翻转名称的排列可能是必要的,但如果在大型数据集中手动完成,可能会很乏味。

本教程向您展示如何在 Excel 中轻松地重新排列姓名,无论您是将姓名从“名字姓氏”翻转为“姓氏,名字”(带或不带逗号)还是相反。无论您需要简单的交换还是涉及高级功能或脚本的更复杂的解决方案,我们都能满足您所需的一切。


使用快速填充翻转名字和姓氏

Excel的 Flash填充 功能是一种智能高效的工具,可根据您提供的模式自动填充数据。这使得它非常适合颠倒数据集中名字和姓氏的顺序等任务。请按照以下简单步骤使用“快速填充”来翻转姓名:

  1. 在您姓名旁边的空列的第一个单元格中(例如, B2),输入单元格中的名称 A2 以相反的顺序:“姓,名".
  2. 选择同一列中的下一个单元格,然后输入单元格中的反向名称 A3. 当您开始输入时,快速填充功能将识别该模式并根据该模式自动填充剩余的单元格。
  3. 媒体 输入 确认快速填充建议。

    提示: 作为步骤 2 和 3 的替代方法,您可以按 按Ctrl + E 在键盘上,或转到 时间 功能区上的选项卡,然后单击 Flash填充 按钮用您提供的模式填充下面的单元格 B2.

笔记:

  • 如果您不想包含逗号或希望将顺序从“姓氏、名字”恢复为“名字姓氏”,则此方法同样有效。关键是提供您希望看到的复制的初始模式。

  • 如果有些姓名有中间名,有些则没有,快速填充可能无法无缝处理它们。为了在这些情况下获得更好的结果,请参阅 人工智能方法 在下一节中描述。
  • Flash Fill提供了固定的解决方案;通过此方法反转的名称保持静态,这意味着它们不会随着原始名称的更改或新条目的添加而动态更新。对于自动更新的动态解决方案, 公式法 被推荐。

使用 AI 切换名字和姓氏

Kutools for Excel 配备人工智能助手, 人工智能助手,旨在轻松颠倒名称顺序,无论它们是否包含中间名。利用用户友好的界面 Kutools 人工智能助手,您可以根据需要轻松颠倒单个或多个选定范围中的名称顺序。请按照以下步骤操作:

请注意: 使用AI操作后,撤消功能将不可用。建议在进行任何人工智能辅助修改之前创建原始数据的备份。

下载 Kutools for Excel to access the feature and unlock your 30-day free trial!
  1. 导航到 库工具 Excel 功能区上的选项卡并选择 人工智能助手 打开 Kutools 人工智能助手 界面。
  2. 选择要翻转的名称。
  3. 在输入框中清楚地键入您的命令。例如,您可以输入:“将所选内容中的姓氏移到前面,后跟逗号".
  4. 媒体 输入 或打 提交 按键 .

  5. Kutools 人工智能助手 及时处理您的命令,提出解决方案。只需单击 执行 按钮以对所选数据应用重新排列。

结果

所选单元格中的所有姓氏均移至前面,后跟逗号。

如果结果不符合您的期望,提示:
  1. 只需点击即可 不满意 按钮。 Kutools 人工智能助手 然后将撤消相反的操作并生成适合您需求的详细分步指南。

  2. 考虑重新表述您的命令,看看它是否会产生更令人满意的结果。

请注意: 想要访问 Kutools 人工智能助手? 下载 Kutools for Excel 现在! 除此之外,Kutools 还拥有 300 多个其他功能,并提供 30 天免费试用。 不要等待,今天就尝试一下吧!


使用公式反转名字和姓氏

要使用公式反转 Excel 中的名字和姓氏,您可以依靠 Excel 的文本操作功能。当您需要一个在原始名称更改时自动更新的动态解决方案时,此方法特别有用。请按照以下步骤实施该公式:

  1. 假设您要反转的名称位于列中 A, 从...开始 A2。选择要显示反转名称的列中的第一个单元格 (B2 在我们的例子中),然后输入公式:
    =REPLACE(A2,1,SEARCH(" ",A2),"")&", "&LEFT(A2,SEARCH(" ",A2)-1)
    提示: 在提供的公式中,确保替换 A1 与包含您想要反转的名称的实际单元格引用。
  2. 拖动单元格右下角的填充柄 B2 向下将公式应用于所有相关单元格。

提示:
  • 如果您不想包含逗号而只包含空格,请考虑使用以下公式:
    =MID(A2&" "&A2,FIND(" ",A2)+1,LEN(A2))

  • 如果您希望将顺序从“姓氏、名字”恢复为“名字姓氏”,请使用以下公式:
    =MID(A2&" "&A2,FIND(", ",A2)+2,LEN(A2)-1)

(AD)使用 Kutools for Excel 轻松反转文本顺序

是否正在努力反转 Excel 单元格中的文本,无论是单独翻转每个字母还是围绕特定分隔符重新排列文本? Kutools for Excel 让一切变得简单!

随着 反向文字顺序 功能,您可以快速反转单元格内的字母或反转由您选择的分隔符分隔的文本段 - 所有这些都通过一个简单的对话框完成!

Kutools for Excel:集成AI🤖,300+便捷的Excel功能触手可及。 现在就开始 30 天免费试用,没有任何功能限制!


使用交换名字和姓氏 Power Query

运用 Power Query in Excel 是一种用于操作和转换数据的强大方法,包括在插入您选择的分隔符时交换名字和姓氏的位置。请按照以下详细步骤完成此任务 Power Query:

请注意: 选择 Power Query 方法 专门针对特定场景:如果 Power Query 已经是数据转换工作流程的一部分,并且您需要集成名称反转,或者如果您经常面临类似的任务。对于一次性名称反转的需求,可以使用更简单的替代方案,例如 Flash填充, AI公式 (如本指南前面所述)可能是更合适和直接的解决方案。

  1. 选择包含要反转的名称的范围。
  2. 导航到 时间 标签并点击 从表/范围 ,在 获取和转换数据 组。
  3. 如果您的数据不是表格格式,Excel 将提示您创建表格。请点击 OK.

  4. Power Query 编者 打开后,右键单击名称列的标题,然后选择 拆分列 > 按分隔符.

  5. 选择分隔符 分隔您的姓名(通常是空格)并选择 在每次出现分隔符时进行分割,然后点击 OK.

  6. 拆分后,您将有两列用于显示名字和姓氏。手动将保留姓氏的列拖动到第一列。

  7. 按住选择要合并的列 按Ctrl 键并单击每一个。然后,右键单击任意列标题并选择 合并列.

  8. 合并列 对话框,从 分隔器 下拉列表中,选择 定制版 选项并输入一个逗号,后跟一个空格 (, ) 为分隔符。如果需要的话, 指定一个名称 对于合并列,然后单击 OK.

  9. 对预览满意后,单击 关闭并加载 按钮在 Power Query 编者 应用您的更改。

结果

Power Query 将立即将转换后的数据输出到 Excel 中的新工作表中。

提示: 此方法在原始数据和转换后的输出之间创建链接。对原始数据的任何更新都可以通过刷新轻松应用于转换后的输出:只需右键单击输出表并选择 刷新.


使用 VBA 交换名字和姓氏

您还可以使用 VBA 宏快速翻转列中的名字和姓氏。对于喜欢使用编码方法在 Excel 中高效操作数据的任何人来说,此方法是理想的选择。

请注意: 在运行此 VBA 脚本之前,强烈建议创建数据备份,因为无法使用标准 Excel 撤消功能撤消 VBA 操作。

  1. 按住 Alt + F11键 在Excel中打开键 Microsoft Visual Basic应用程序 窗口。
  2. 点击 插页 > 模块,并将以下宏粘贴到 模块 窗口。
    Sub FlipName()
    'Update by ExtendOffice on 20240327
    Dim xRng As Range
    Dim xWorkRng As Range
    Dim xSign As String
    Dim xSeparator As String
    On Error Resume Next
    xTitleId = "Kutools for Excel"
    Set xWorkRng = Application.Selection
    Set xWorkRng = Application.InputBox("Flip names in the range:", xTitleId, xWorkRng.Address, Type:=8)
    xSign = Application.InputBox("Input the separator used within names:", xTitleId, Type:=2)
    For Each xRng In xWorkRng
        xValue = xRng.Value
        NameList = VBA.Split(xValue, xSign)
        If UBound(NameList) = 1 Then
            xRng.Value = NameList(1) & ", " & NameList(0)
        End If
    Next
    End Sub

    请注意: 该宏会自动在颠倒的名称之间插入逗号。如果您想使用不同的分隔符,您可以修改代码片段 xRng.Value = NameList(1) & ", " & NameList(0) 在代码的第16行找到。例如,替换 “”“” 将用空格而不是逗号分隔名称。

  3. F5 运行此宏的键。 在弹出 Kutools for Excel 对话框中,选择包含要翻转的名称的范围,然后单击 OK 按钮。

  4. 在下一个对话框中,请输入名称中使用的现有分隔符(例如我们示例中的空格),然后单击 OK 按钮。

结果

现在,所选范围内的名字和姓氏会翻转。


以上就是Excel中翻转姓名相关的全部内容。我希望本教程对您有所帮助。如果您想探索更多 Excel 提示和技巧, 请点击这里 访问我们广泛收集的超过数千个教程。

Comments (42)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
It worked for me.
Thank you!
This comment was minimized by the moderator on the site
hola, gracias por tus formulas, como puedo hacer si necesito reversar los nombres y luego los apellidos, por ejemplo tengo esto GRANDA VELASCO OMAR GERMANICO, y con la función revert no me funciona en orden me saca GERMANICO OMAR VELASCO GRANDA, me cambia el orden.
This comment was minimized by the moderator on the site
Hi there,

If you have additional middle names rather than just first and last names, please try the Reverse Text Order feature of Kutools for Excel.
https://www.extendoffice.com/images/stories/comments/ljy-picture/reverse-text.png

If you don't have Kutools for Excel installed in your computer, you can click here to download and try it for free for 30 days: Kutools for Excel. After the installation, you can find the feature on Kutools tab, in Editing group:
https://www.extendoffice.com/images/stories/comments/ljy-picture/reverse-text-2.png

Amanda
This comment was minimized by the moderator on the site
Thank you sooo very much! You made work easier for me!
This comment was minimized by the moderator on the site
=MID(A2&", "&A2,FIND(" ",A2)+1,LEN(A2)+1)

where the name is on the A2 cell
This comment was minimized by the moderator on the site
You saved my life!!! Thank you. None of the others worked. This is exactly what I needed.
This comment was minimized by the moderator on the site
=MID(O4&", "&O4,FIND(" ",O4)+1,LEN(O4)+1)
This comment was minimized by the moderator on the site
okay. can someone say this in english because I have no clue what you guys are talking about
This comment was minimized by the moderator on the site
Try this to add a comma: =MID(A2&", "&A2,FIND(" ",A2)+1,LEN(A2)+1)
This comment was minimized by the moderator on the site
THANK YOU literally I've been trying to figure out the comma thing for like an hour. Thank you!
This comment was minimized by the moderator on the site
What if I need to insert a comma between the last and first name?
This comment was minimized by the moderator on the site
What if there is a comma separating the 2 names? Is there a way to eliminate it? Now the names look like

Arthur Lange,

Eric Norris,

etc etc
This comment was minimized by the moderator on the site
Try this to remove a comma: =MID(A2&" "&A2,FIND(", ",A2)+1,LEN(A2)+1)
This comment was minimized by the moderator on the site
Have you tried Ctrl+F, Select Replace, Find "," and leave replace with blank.
This comment was minimized by the moderator on the site
When I try that, it pops up with this error message "There's a problem with this formula. Not trying to type a formula? When the first character is an equal (=) or minus (-) sign, Excel thinks it's a formula: you type: =1+1, cell shows: 2. To get around this, type an apostrophe (') first: you type: '=1+1, cell shows =1+1.
This comment was minimized by the moderator on the site
I think you are changing the formula. Try copying and pasting the values to a new cell then do the find/replace.
This comment was minimized by the moderator on the site
I want to know this too!
This comment was minimized by the moderator on the site
Correction. What if i have four names? What's the formula? Last name - first name - middle1 - middle2
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations