如何反转excel中一列中每个单元格中的名字和姓氏_如何使用excel公式或excel VBA宏翻转名字和姓氏
时间:2022-10-26 19:03:02
本文将讲述如何在Excel的一列中翻转或反转名字和姓氏。如何反转excel中一列中每个单元格中的名字和姓氏。如何使用excel公式或excel VBA宏翻转名字和姓氏。
如果需要反转单元格区域中的名字和姓氏,然后将结果放入另一列中的单元格中。您需要首先获取或提取名字或姓氏,然后将这些名称组合到同一个单元格中。您可以编写excel公式或编写新的Excel VBA代码来实现反转。
使用Excel公式反转名字和姓氏
要反转名字和姓氏,可以根据MID函数,FIND函数和Len函数创建公式,如下所示:
=MID(B2&” ” &B2, FIND(” “,B2)+1, LEN(B2))
让我们看看这个公式是如何工作的:
=B2&” ” &B2
此公式将使用连接运算符将B2中的文本字符串与B2中的文本字符串再次连接以生成新的文本字符串。然后我们只需要从新文本字符串中提取第二个和第三个单词。
= FIND(” “,B2)+1
此公式将返回Cell B2的文本字符串中第一个空格字符的位置。然后它将作为其start_num参数传递给MID函数。
= LEN(B2)
它将返回Cell B2中文本字符串的长度,然后它将作为num_chars参数传递给MID函数。
=MID(B2&” ” &B2, FIND(” “,B2)+1, LEN(B2))
使用Excel VBA宏反转名字和姓氏
您也可以编写一个excel宏来反转名字和姓氏,您可以参考以下步骤:
步骤1:打开您的Excel工作簿,然后单击开发工具选项卡下的“Visual Basic”命令,或者只需按“ALT + F11”快捷方式。
步骤2:然后将出现“Visual Basic编辑器”窗口。
步骤3:单击“插入” – >“模块”以创建新模块。
步骤4:将以下VBA代码粘贴到代码窗口中。然后单击“保存”按钮。
Sub ReverseName()
Set myRange = Application.Selection
Set myRange = Application.InputBox("Select one Range that you want to reverse name", "ReverseName", myRange.Address, Type:=8)
myDelemiter = Application.InputBox("Please type a delimiter character:", "ReverseName", " ", Type:=2)
For Each myCell In myRange
xValue = myCell.Value
NameList = VBA.Split(xValue, myDelemiter)
If UBound(NameList) = 1 Then
myCell.Value = NameList(1) + myDelemiter + NameList(0)
End If
Next
End Sub
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
excel表格怎么使用VBA一次性声明多个变量?
![](https://img.aspxhome.com/file/2023/5/40085_0s.png)
如何取消word文档中的小箭头
![](https://img.aspxhome.com/file/2023/9/18699_0s.jpg)
excel如何从车牌号中提取省的简称 excel从车牌号中提取省的简称方法
![](https://img.aspxhome.com/file/2023/2/39672_0s.jpg)
win10显卡驱动怎么更新?win10显卡驱动更新方法教程
![](https://img.aspxhome.com/file/2023/4/47444_0s.png)
surface预装office如何激活
![](https://img.aspxhome.com/file/2023/6/16716_0s.png)
Word文档自动保存怎么设置?
![](https://img.aspxhome.com/file/2023/6/34766_0s.gif)
windows10开机黑屏只有鼠标指针怎么办?windows10开机黑屏只有鼠标指针解决教程
![](https://img.aspxhome.com/file/2023/8/48028_0s.jpg)
wps怎样设置ppt背景音乐
![](https://img.aspxhome.com/file/2023/2/53452_0s.jpg)
word 2010 界面介绍
![](https://img.aspxhome.com/file/2023/5/24745_0s.jpg)
如何在Word文档里插入另一篇文档
![](https://img.aspxhome.com/file/2023/5/18335_0s.jpg)
word怎样对插入的图片排版
怎么添加excel工作表个数
![](https://img.aspxhome.com/file/2023/3/36913_0s.png)
iOS 版微信已开始支持通过 Apple Watch 付款
![](https://img.aspxhome.com/file/2023/8/45788_0s.png)
Word中分节符的奇妙用法
苹果为何简化“Hey Siri”?
![](https://img.aspxhome.com/file/2023/9/44959_0s.png)
Win10桌面图标大小怎么更改?Win10桌面图标大小更改方法介绍
![](https://img.aspxhome.com/file/2023/6/51276_0s.png)
怎样设置Word2013文档的纸张大小
![](https://img.aspxhome.com/file/2023/6/20956_0s.jpg)
word 2013中如何创建表格
![](https://img.aspxhome.com/file/2023/4/32834_0s.jpg)
怎么关闭win10的自动更新?关闭win10的自动更新方法
![](https://img.aspxhome.com/file/2023/1/47931_0s.png)
利用word画虚线,画折线图,画曲线图的方法
![](https://img.aspxhome.com/file/2023/8/24098_0s.jpg)