本文主要是介绍excel表格自动填充为汉字拼音首字母,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
更改自:https://jingyan.baidu.com/article/75ab0bcb26da9f96874db22d.html
环境说明
microsoft excel 2016
操作步骤
1、打开【Excel表格】,选中sheet表,右键-》查看代码;或者按组合快捷键【Alt+F11】,打开【Visual Basic编辑器】:
2、点击上面菜单栏的【插入】选项,然后选择【模板】,如下图所示:
3、将下面的代码复制到窗口中(该代码就是取汉语拼音首字母的一个程序):
Function getpychar(char)tmp = 65536 + Asc(char)If (tmp >= 45217 And tmp <= 45252) Thengetpychar = "A"ElseIf (tmp >= 45253 And tmp <= 45760) Thengetpychar = "B"ElseIf (tmp >= 45761 And tmp <= 46317) Thengetpychar = "C"ElseIf (tmp >= 46318 And tmp <= 46825) Thengetpychar = "D"ElseIf (tmp >= 46826 And tmp <= 47009) Thengetpychar = "E"ElseIf (tmp >= 47010 And tmp <= 47296) Thengetpychar = "F"ElseIf (tmp >= 47297 And tmp <= 47613) Thengetpychar = "G"ElseIf (tmp >= 47614 And tmp <= 48118) Thengetpychar = "H"ElseIf (tmp >= 48119 And tmp <= 49061) Thengetpychar = "J"ElseIf (tmp >= 49062 And tmp <= 49323) Thengetpychar = "K"ElseIf (tmp >= 49324 And tmp <= 49895) Thengetpychar = "L"ElseIf (tmp >= 49896 And tmp <= 50370) Thengetpychar = "M"ElseIf (tmp >= 50371 And tmp <= 50613) Thengetpychar = "N"ElseIf (tmp >= 50614 And tmp <= 50621) Thengetpychar = "O"ElseIf (tmp >= 50622 And tmp <= 50905) Thengetpychar = "P"ElseIf (tmp >= 50906 And tmp <= 51386) Thengetpychar = "Q"ElseIf (tmp >= 51387 And tmp <= 51445) Thengetpychar = "R"ElseIf (tmp >= 51446 And tmp <= 52217) Thengetpychar = "S"ElseIf (tmp >= 52218 And tmp <= 52697) Thengetpychar = "T"ElseIf (tmp >= 52698 And tmp <= 52979) Thengetpychar = "W"ElseIf (tmp >= 52980 And tmp <= 53640) Thengetpychar = "X"ElseIf (tmp >= 53679 And tmp <= 54480) Thengetpychar = "Y"ElseIf (tmp >= 54481 And tmp <= 62289) Thengetpychar = "Z"Else '如果不是中文,则不处理getpychar = charEnd IfEnd Function'逐个取ASC码Function getpy(str)For i = 1 To Len(str)getpy = getpy & getpychar(Mid(str, i, 1))Next iEnd Function
4、关闭Visual Basic编辑窗口,回到Excel表格中,如下图所示:
5、在B2单元格中输入公式【=getpy(A2)】,然后按【回车键】,如下图所示:
6、将鼠标移到B2单元格右下角呈+号时下拉填充公式即可,如下图所示:
这篇关于excel表格自动填充为汉字拼音首字母的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!