excel自动提取姓名首字母拼音(中文怎么快速转成拼音呢)

用Excel收集统计个人信息时,会遇见各种各样的问题。例如:我们需要将中文姓名转换成首字母拼音的形式,这时候该怎么操作呢?

你还在一个一个的输入吗?这样太麻烦了,接下来让我们使用VBA,快速将中文转换成拼音首字母的形式,简单便捷,快来试试吧!

excel自动提取姓名首字母拼音(中文怎么快速转成拼音呢)(1)

打开Microsoft Excel工作簿,如果Excel文件后缀名是“xlsx”,请先将Excel文档另存为“xls”或者“xlsm”类型。

右键单击Sheet1工作表,选中右键菜单中的查看代码。

excel自动提取姓名首字母拼音(中文怎么快速转成拼音呢)(2)

在Microsoft Visual Basic for Applications窗口中,右键单击工程资源管理器窗口中的空白位置,将鼠标指针移动至插入,选中模块。

接着将以下代码复制粘贴至模块1的代码窗口中,点击保存后退出Visual Basic编辑器。

excel自动提取姓名首字母拼音(中文怎么快速转成拼音呢)(3)

代码区域

Function Getpychar(char)

temp = 65536 Asc(char)

If (temp >= 45217 And temp <= 45252) Then

Getpychar = "A"

ElseIf (temp >= 45253 And temp <= 45760) Then

Getpychar = "B"

ElseIf (temp >= 45761 And temp <= 46317) Then

Getpychar = "C"

ElseIf (temp >= 46318 And temp <= 46825) Then

Getpychar = "D"

ElseIf (temp >= 46826 And temp <= 47009) Then

Getpychar = "E"

ElseIf (temp >= 47010 And temp <= 47296) Then

Getpychar = "F"

ElseIf (temp >= 47297 And temp <= 47613) Then

Getpychar = "G"

ElseIf (temp >= 47614 And temp <= 48118) Then

Getpychar = "H"

ElseIf (temp >= 48119 And temp <= 49061) Then

Getpychar = "J"

ElseIf (temp >= 49062 And temp <= 49323) Then

Getpychar = "K"

ElseIf (temp >= 49324 And temp <= 49895) Then

Getpychar = "L"

ElseIf (temp >= 49896 And temp <= 50370) Then

Getpychar = "M"

ElseIf (temp >= 50371 And temp <= 50613) Then

Getpychar = "N"

ElseIf (temp >= 50614 And temp <= 50621) Then

Getpychar = "O"

ElseIf (temp >= 50622 And temp <= 50905) Then

Getpychar = "P"

ElseIf (temp >= 50906 And temp <= 51386) Then

Getpychar = "Q"

ElseIf (temp >= 51387 And temp <= 51445) Then

Getpychar = "R"

ElseIf (temp >= 51446 And temp <= 52217) Then

Getpychar = "S"

ElseIf (temp >= 52218 And temp <= 52697) Then

Getpychar = "T"

ElseIf (temp >= 52698 And temp <= 52979) Then

Getpychar = "W"

ElseIf (temp >= 52980 And temp <= 53640) Then

Getpychar = "X"

ElseIf (temp >= 53689 And temp <= 54480) Then

Getpychar = "Y"

ElseIf (temp >= 54481 And temp <= 62289) Then

Getpychar = "Z"

Else

Getpychar = char

End If

End Function

Function Getpy(str)

For a = 1 To Len(str)

Getpy = Getpy & Getpychar(Mid(str, a, 1))

Next a

End Function

excel自动提取姓名首字母拼音(中文怎么快速转成拼音呢)(4)

例如单元格区域C:C是中文姓名,需要在单元格区域D:D转换成拼音首字母形式。只需在D2单元格中输入函数“=Getpy(C2)”,然后进行单元格填充就可以啦。

excel自动提取姓名首字母拼音(中文怎么快速转成拼音呢)(5)

是不是非常简单便捷呢?抓紧时间把代码收藏起来吧,有备无患。

点击关注、转发和收藏,有更多计算机小技巧等着您来发现。

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页