Excel自定义函数取拼音首字母

1.启动Excel 2003(其它版本请仿照操作),打开相应的工作表;

2.执行"工具 > 宏 > Visual Basic编辑器"命令(或者直接按"Alt+F11"组合键),进入Visual Basic编辑状态;

3.执行"插入 > 模块"命令,插入一个新模块。再双击插入的模块,进入模块代码编辑状态

4.将代码输入其中。代码如下:

复制代码
Function pinyin(p As String) As String
 
i = Asc(p)
 
Select Case i
 
Case -20319 To -20284: pinyin = "a"
 
Case -20283 To -19776: pinyin = "b"
 
Case -19775 To -19219: pinyin = "c"
 
Case -19218 To -18711: pinyin = "d"
 
Case -18710 To -18527: pinyin = "e"
 
Case -18526 To -18240: pinyin = "f"
 
Case -18239 To -17923: pinyin = "g"
 
Case -17922 To -17418: pinyin = "h"
 
Case -17417 To -16475: pinyin = "j"
 
Case -16474 To -16213: pinyin = "k"
 
Case -16212 To -15641: pinyin = "l"
 
Case -15640 To -15166: pinyin = "m"
 
Case -15165 To -14923: pinyin = "n"
 
Case -14922 To -14915: pinyin = "o"
 
Case -14914 To -14631: pinyin = "p"
 
Case -14630 To -14150: pinyin = "q"
 
Case -14149 To -14091: pinyin = "r"
 
Case -14090 To -13319: pinyin = "s"
 
Case -13318 To -12839: pinyin = "t"
 
Case -12838 To -12557: pinyin = "w"
 
Case -12556 To -11848: pinyin = "x"
 
Case -11847 To -11056: pinyin = "y"
 
Case -11055 To -2050: pinyin = "z"
 
Case Else: pinyin = p
 
End Select
 
End Function

Function getpy(str)
 
For i = 1 To Len(str)
 
getpy = getpy & pinyin(Mid(str, i, 1))
 
Next i
 
End Function

5.代码输入完成后,关闭Visual Basic编辑窗口,返回Excel编辑状态;

6.自定义函数就可以用了,如:选中A2单元格,输入公式:=getpy(A2)

相关推荐
Oll Correct3 小时前
Excel基础操作(三)
笔记·excel
讓丄帝愛伱4 小时前
excel导出实例
java·python·excel
Lilixxs5 小时前
Excel VBA离线帮助文档下载和使用
excel·vba·帮助文档·ms help runtime·hxs
梦幻通灵13 小时前
Excel的TEXT函数实战【持续更新】
excel
陈奕昆16 小时前
n8n实战营Day2课时2:Loop+Merge节点进阶·Excel批量校验实操
人工智能·python·excel·n8n
诸神缄默不语19 小时前
Python 3中的win32com使用教程+示例:从Excel读取数据生成Word格式报告批量发邮件
python·word·excel
_大龄2 天前
前端解析excel
前端·excel
johnny2333 天前
智能电子表格:Airtable、NocoDB、teable、APITable
excel
2501_930707783 天前
如何使用C#代码在Excel 文件中添加工作表
excel
shouchaobao3 天前
免费PDF工具:PDF转Word/Excel/图片+AI总结+合并拆分+OCR识别,多端无广告!
pdf·word·excel