excel:汉字拼音首字母提取
excel提取汉子首字母
1.首先,打开Excel,同时按下Alt+F11键,打开VBE界面,如下图所示。
在VBE界面中,单击图片中所示的左上角空白处,选择“插入“,”模块“。
2.此时,就插入了一个模块,后面的代码就要放到这个模块中,保证右侧空白区域是模块代码的编辑区(最保险的做法是双击模块),然后执行下一步操作。
3.将下面的代码全部复制粘贴到空白区域。
Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy & pinyin(Mid(str, i, 1)) Next iEnd Function4.然后关闭这个新界面,返回Excel,就可以像Excel自带的函数一样使用这个自定义的Getpy函数了,它只有一个参数,参数可以直接指定单元格,也可以直接输入字符。
表格中提取词语首字母的方法
表格中提取词语首字母的方法
要提取表格中词语的首字母,你可以使用Excel或类似的电子
表格软件来实现。
以下是一种可能的方法:
1. 使用公式提取首字母,在Excel中,你可以使用LEFT函数
来提取单元格中文本的首字母。
假设你要提取A列中单元格的首字母,你可以在B列中使用以下公式,=LEFT(A1,1),然后拖动填充手
柄以应用到其他单元格。
这将在B列中显示A列中单元格的首字母。
2. 使用文本转换功能,在Excel中,你还可以使用文本转换功
能来将单元格中的文本转换为大写或小写,然后提取首字母。
例如,你可以使用函数=UPPER(LEFT(A1,1))来将A列中单元格的首字母转
换为大写形式。
3. 使用宏,如果你熟悉VBA编程,你还可以编写一个宏来自动
提取表格中单元格的首字母。
这样可以实现自动化处理大批量数据
的目的。
总之,以上是几种常见的方法,你可以根据具体情况选择适合
你的方法来提取表格中词语的首字母。
希望这些方法能够帮到你。
Excel中进行用函数实现提取汉子首字母的操作技巧
Excel中进行用函数实现提取汉子首字母的操作技巧有一些场合,要用到汉字的首字母缩写,而Excel中并没有这样一个函数,可以直接提取汉字的首字母。
今天,店铺就教大家在Excel中进行用函数实现提取汉子首字母的操作技巧。
Excel中进行用函数实现提取汉子首字母的操作步骤首先,打开Excel,同时按下Alt+F11键,打开VBE界面,如下图所示。
在VBE界面中,单击图片中所示的左上角空白处,选择“插入“,”模块“。
此时,就插入了一个模块,后面的代码就要放到这个模块中,保证右侧空白区域是模块代码的编辑区(最保险的做法是双击模块),然后执行下一步操作。
将下面的代码全部复制粘贴到空白区域。
Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy & pinyin(Mid(str, i, 1))Next iEnd Function然后关闭这个新界面,返回Excel,就可以像Excel自带的函数一样使用这个自定义的Getpy函数了,它只有一个参数,参数可以直接指定单元格,也可以直接输入字符。
excel中实现提取汉字的拼音首字母
在EXECL中,按ALT+F11,插入---模块复制下列代码:Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As Integer, hzi As Integer, hzpyhex As Integerhzstring = Trim(hzpy)hzpysum = Len(Trim(hzstring))pystring = ""For hzi = 1 To hzpysumhzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))Select Case hzpyhexCase &HB0A1 To &HB0C4: pystring = pystring + "A"Case &HB0C5 To &HB2C0: pystring = pystring + "B"Case &HB2C1 To &HB4ED: pystring = pystring + "C"Case &HB4EE To &HB6E9: pystring = pystring + "D"Case &HB6EA To &HB7A1: pystring = pystring + "E"Case &HB7A2 To &HB8C0: pystring = pystring + "F"Case &HB8C1 To &HB9FD: pystring = pystring + "G"Case &HB9FE To &HBBF6: pystring = pystring + "H"Case &HBBF7 To &HBFA5: pystring = pystring + "J"Case &HBFA6 To &HC0AB: pystring = pystring + "K"Case &HC0AC To &HC2E7: pystring = pystring + "L"Case &HC2E8 To &HC4C2: pystring = pystring + "M"Case &HC4C3 To &HC5B5: pystring = pystring + "N"Case &HC5B6 To &HC5BD: pystring = pystring + "O"Case &HC5BE To &HC6D9: pystring = pystring + "P"Case &HC6DA To &HC8BA: pystring = pystring + "Q"Case &HC8BB To &HC8F5: pystring = pystring + "R"Case &HC8F6 To &HCBF9: pystring = pystring + "S"Case &HCBFA To &HCDD9: pystring = pystring + "T"Case &HEDC5: pystring = pystring + "T"Case &HCDDA To &HCEF3: pystring = pystring + "W"Case &HCEF4 To &HD1B8: pystring = pystring + "X"Case &HD1B9 To &HD4D0: pystring = pystring + "Y"Case &HD4D1 To &HD7F9: pystring = pystring + "Z"Case Elsepystring = pystring + Mid(hzstring, hzi, 1)End SelectNexthztopy = pystringEnd Function比如在A1输入小燕子耳坠子7.8 则在其他空白单元格输入=hztopy(A1) 回车执行即可。
excel汉字转换成拼音简拼(只取首字母)
打开Excel->工具->宏->Viaual Basic编辑器在弹出来的窗口中对着VBAproject点右键->插入->模块下面会出现一个名为"模块1",点击在右边的空白栏中粘贴以下内容:Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy & pinyin(Mid(str, i, 1))Next iEnd Function********复制到此结束,本行不复制*******现在转换函数已编写完成!关掉此编缉的窗口。
EXCEL中怎么把汉字变成拼音,并取拼音的第一个大写字母
打开Excel->工具->宏->Viaual Basic编辑器在弹出来的窗口中对着VBAproject点右键->插入->模块下面会出现一个名为"模块1",点击在右边的空白栏中粘贴以下内容:Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy & pinyin(Mid(str, i, 1))Next iEnd Function********复制到此结束,本行不复制*******现在转换函数已编写完成!关掉此编缉的窗口。
excel获得汉字首字母的方法
在日常工作和学习中,我们经常需要对文本进行处理和分析,尤其是对于中文文本。
在处理中文文本时,有时会遇到需要将汉字转换为拼音的需求。
而在Excel中,获得汉字的首字母则成为了一个常见的需求。
那么,如何在Excel中获得汉字的首字母呢?我们可以利用Excel内置的函数来实现这一目标。
在Excel中,可以使用VB脚本编写一个自定义函数来获取汉字的首字母。
具体步骤如下:1. 打开Excel表格,按下ALT + F11,打开VB编辑器。
2. 在VB编辑器中,插入一个新模块。
3. 在新模块中输入以下VB脚本代码:```vbFunction GetFirstLetter(str As String) As StringDim pinyin As StringDim i As IntegerDim ch As Stringpinyin = ""For i = 1 To Len(str)ch = Mid(str, i, 1)pinyin = pinyin &Left(Application.WorksheetFunction.Phonetic(ch), 1)Next iGetFirstLetter = pinyinEnd Function```4. 编译保存后,返回Excel表格界面。
5. 在需要获取汉字首字母的单元格中输入`=GetFirstLetter(A1)`,其中A1为需要转换的汉字所在的单元格。
6. 按下Enter键,即可在目标单元格中获取到相应汉字的首字母。
通过上述方法,我们可以轻松地在Excel中获得汉字的首字母,而且可以将这个函数在多个单元格中批量应用,提高工作效率。
除了使用VB脚本自定义函数外,我们还可以借助Excel内置的函数来实现汉字首字母的获取。
在Excel中,有一个叫做UNICODE的函数,可以返回指定字符的Unicode编码。
而对于汉字来说,其首字母的Unicode编码可以作为其拼音的首字母。
excel:汉字拼音首字母提取
方法一:VBA自定义函数"=hztopy()"下面是一个VBA自定义函数,工具->宏->Visual Basic编辑器->,插入模块,在VBA编辑器里面->插入->模块->贴入下述代码,(按ALT+F11,插入模块,在右面窗口中粘贴下面代码)那么,比如在A3中有"进退两难",则在B3中输入"=hztopy(A3)",则会得到"JTLN"。
不过此法有时候也会出错,比如"皓、鑫、婷、雯、奕"等,就无法提取汉字拼音首字母。
Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As Integer, hzi As Integer, hzpyhex As Integerhzstring = Trim(hzpy)hzpysum = Len(Trim(hzstring))pystring = ""For hzi = 1 To hzpysumhzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))Select Case hzpyhexCase &HB0A1 To &HB0C4: pystring = pystring + "A"Case &HB0C5 To &HB2C0: pystring = pystring + "B"Case &HB2C1 To &HB4ED: pystring = pystring + "C"Case &HB4EE To &HB6E9: pystring = pystring + "D"Case &HB6EA To &HB7A1: pystring = pystring + "E"Case &HB7A2 To &HB8C0: pystring = pystring + "F"Case &HB8C1 To &HB9FD: pystring = pystring + "G"Case &HB9FE To &HBBF6: pystring = pystring + "H"Case &HBBF7 To &HBFA5: pystring = pystring + "J"Case &HBFA6 To &HC0AB: pystring = pystring + "K"Case &HC0AC To &HC2E7: pystring = pystring + "L"Case &HC2E8 To &HC4C2: pystring = pystring + "M"Case &HC4C3 To &HC5B5: pystring = pystring + "N"Case &HC5B6 To &HC5BD: pystring = pystring + "O"Case &HC5BE To &HC6D9: pystring = pystring + "P"Case &HC6DA To &HC8BA: pystring = pystring + "Q"Case &HC8BB To &HC8F5: pystring = pystring + "R"Case &HC8F6 To &HCBF9: pystring = pystring + "S"Case &HCBFA To &HCDD9: pystring = pystring + "T"Case &HEDC5: pystring = pystring + "T"Case &HCDDA To &HCEF3: pystring = pystring + "W"Case &HCEF4 To &HD1B8: pystring = pystring + "X"Case &HD1B9 To &HD4D0: pystring = pystring + "Y"Case &HD4D1 To &HD7F9: pystring = pystring + "Z"Case Elsepystring = pystring + Mid(hzstring, hzi, 1)End SelectNexthztopy = pystringEnd Function方法二:VBA自定义函数"=getpy()"下面是一个VBA自定义函数,工具->宏->Visual Basic编辑器->,插入模块,在VBA编辑器里面->插入->模块->贴入上述代码,那么。
excel_汉字转换成拼音简拼(只取首字母)
excel_汉字转换成拼音简拼(只取首字母)名称转换为首字母(VBA自定义函数)1,打开EXCEL2,按ALT+F11,单击插入-插入模块,在右窗口粘贴以下代码,直接关闭窗口3,输入公式=hztopy(A1),填充所有单元格4,选择所有缩写,复制-粘贴特殊值(因为它是自定义函数,只有结果可以显示在当前文件中,而其他计算机显示错误是因为5.使用条件格式检索包含中文字符的单元格:首先单击一个单元格(设置为D5)。
条件格式-新格式规则-使用公式确定要格式化的单元格:在下面的对话框中输入公式= LEMB(D5)> LEN(D5),自己设置格式,确认后退出,然后用单元格的格式刷所有单元格汉字外观的格式设置为6。
选择自定义排序-按“单元格颜色”排序-排序“无单元格颜色”和“底部”-确定7,手动将汉字改写成相应的字母8、检查复音字符注意:上述方法只能在当前文件夹中使用。
如何保存宏以便自定义函数可以在所有文件夹中使用?1.创建新的EXCEL2。
按ALT+F11,单击插入-插入模块,并在右侧窗口中粘贴以下代码。
直接关闭窗口3,另存为-其他格式-文件名更改为宏名,保存类型选择” EXCEL加载项(*,xlam)”,文件将自动保存在c: \ \用户\ \ 111 \ \ appdata \ \ road ing \ \ Microsoft \ \ addins文件夹中4.打开需要工作的EXL,然后单击开始-扩展选项-加载项-转到(G)...-选择上面保存的宏名-确定这样,在这台计算机的所有EXCEL中,可以直接使用自定义公式。
代码(只复制星号的内容)* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *函数Hz topy(hzpy As String)As String Dim hzstring As String,py String As StringDim hzpy sum As Integer,hzi As Integer,hzpyhex As Integer hzstring = Trim(hzpy)hzpy sum = Len(Trim(hzstring))py String = \For hzi = 1 To hzpy sumhzpyhex = \ Select Case hzpyhexCase & HB 案例&HB2C1至&HB4ED: pystring = pystring + \案例&HB4EE至&HB6E9: pystring = pystring + \案例&HB6EA至&HB7A1: pystring = pystring + \案例&HB7A2至&HB8C0: pystring = pystring + \案例&HB8C1至&HB9FD: pystring = pystring + \案例&HB9FE至&HBBF6: pystring = pystring + \案例&HBBF7至&HBFA5: pystring = pystring 案例&HC2E8至&HC4C2: pystring = pystring + \案例&HC4C3至&HC5B5: pystring = pystring + \案例&HC5B6至&HC5BD:pystring = pystring + \案例&HC5BE至&HC6D9: pystring = pystring + \案例&HC6DA至&HC8BA: pystring = pystring + \案例&HC8BB至&HC8F5: pystring = pystring + \案例&HC8F6至&HCBF9: pystring = pystringCase & HCDDA To & HCEF3:py string = py string+\ Case & HCEF4 To & HD1B 8:py string = py string+\ Case & HD1B 9 To & HD4D 0:py string = py string+\ Case & HD4D 1 To & HD7F 9:py string = py string+\ Case Elsepy string = py string+Mid(Hz string,hzi,1)结束选择下一个hztopy = pystring结束。
图解excel中提取中文首字母
汉字中还包含英文字母或数字,英文或数字部分也要返回。
比如:中国航天6号a返回应为:ZGHT6Ha方法:1、打开EXCEL文件,按ALT+F11,弹出代码窗口。
2、点工具栏的:插入——模块。
3、在右面窗口中粘贴下面代码。
4、点保存,关闭并返回EXCEL窗口。
5、若A1内容为中国航天6号a,则在某空白格中输入:=hztopy(A1) 即可复制下面蓝色的代码:Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As Integer, hzi As Integer, hzpyhex As Integer hzstring = Trim(hzpy)hzpysum = Len(Trim(hzstring))pystring = ""For hzi = 1 To hzpysumhzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))Select Case hzpyhexCase &HB0A1 To &HB0C4: pystring = pystring + "A"Case &HB0C5 To &HB2C0: pystring = pystring + "B"Case &HB2C1 To &HB4ED: pystring = pystring + "C"Case &HB4EE To &HB6E9: pystring = pystring + "D"Case &HB6EA To &HB7A1: pystring = pystring + "E"Case &HB7A2 To &HB8C0: pystring = pystring + "F"Case &HB8C1 To &HB9FD: pystring = pystring + "G"Case &HB9FE To &HBBF6: pystring = pystring + "H"Case &HBBF7 To &HBFA5: pystring = pystring + "J"Case &HBFA6 To &HC0AB: pystring = pystring + "K"Case &HC0AC To &HC2E7: pystring = pystring + "L"Case &HC2E8 To &HC4C2: pystring = pystring + "M"Case &HC4C3 To &HC5B5: pystring = pystring + "N"Case &HC5B6 To &HC5BD: pystring = pystring + "O"Case &HC5BE To &HC6D9: pystring = pystring + "P"Case &HC6DA To &HC8BA: pystring = pystring + "Q"Case &HC8BB To &HC8F5: pystring = pystring + "R"Case &HC8F6 To &HCBF9: pystring = pystring + "S"Case &HCBFA To &HCDD9: pystring = pystring + "T"Case &HEDC5: pystring = pystring + "T"Case &HCDDA To &HCEF3: pystring = pystring + "W"Case &HCEF4 To &HD1B8: pystring = pystring + "X"Case &HD1B9 To &HD4D0: pystring = pystring + "Y"Case &HD4D1 To &HD7F9: pystring = pystring + "Z"Case Elsepystring = pystring + Mid(hzstring, hzi, 1)End SelectNexthztopy = pystringEnd Function。
excel查找函数应用:如何提取姓名的拼音首字母
excel查找函数应用:如何提取姓名的拼音首字母编按:哈喽,大家好!如果此刻让你快速提取汉字拼音的首字母,你会怎么做呢?相信大多数小伙伴面对这个问题时,都会蒙圈,可能会想“这应该得用VBA解决吧,函数应该不行吧。
”其实呀,这个问题用大家都会的VLOOKUP函数就能搞定,赶紧来看看吧!例如A列是员工姓名,需要在B列填写对应的拼音首字母:如果遇上这种问题该怎么办?用户来说,难道真的只能一个一个手动输入吗?实际上使用一个大家都非常熟悉的VLOOKUP函数也是可以搞定这个问题的,不过公式嘛,就有点吓人,是这个样子的:看到这个公式是不是都蒙圈了。
可千万不要被这个表面上看起来很夸张的公式吓到,我们换一种写法,也许你就看明白了。
怎么样,这个公式是不是有点看明白了。
与第一个公式的区别就在于,后面这个公式是把VLOOKUP的第二参数放在单元格区域中了,公式的本质并没有什么区别。
因为名单中的姓名都不超过三个字,所以先用MID函数将每个字单独提取出来,使用VLOOKUP得到每个字的拼音首字母,再把三个VLOOKUP函数用&连接起来。
因此公式的核心其实是=VLOOKUP(MID(A2,1,1),$D$1:$E$24,2)。
对于VLOOKUP函数的用法,大家应该都比较熟悉了,格式是:VLOOKUP(查找值,查找区域,在第几列找,怎么找)。
在本例中,要重点说明的有下面几个要点:1.第一参数可以使用公式,本例中分别使用MID(A2,1,1)、MID(A2,2,1)和MID(A2,3,1)作为查找值;2.本例中的VLOOKUP函数只用了三个参数,同时省略了第三参数2后面的逗号,这种写法表示使用了VLOOKUP函数模糊匹配,与第四参数为1的功能相同;3.关于省略VLOOKUP函数最后一个参数的意义,一定要注意一点,省略参数而不省略逗号时,表示精确匹配,与第四参数为0的功能相同;4.有时候为了避免使用单元格区域作为查找区域,第二参数可以使用常量数组的方式,本例中开头的公式就是用到了常量数组。
excel:汉字拼音首字母提取
方法一:VBA自定义函数"=hztopy()"下面是一个VBA自定义函数,工具->宏->Visual Basic编辑器->,插入模块,在VBA编辑器里面->插入->模块->贴入下述代码,(按ALT+F11,插入模块,在右面窗口中粘贴下面代码)那么,比如在A3中有"进退两难",则在B3中输入"=hztopy(A3)",则会得到"JTLN"。
不过此法有时候也会出错,比如"皓、鑫、婷、雯、奕"等,就无法提取汉字拼音首字母。
Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As Integer, hzi As Integer, hzpyhex As Integerhzstring = Trim(hzpy)hzpysum = Len(Trim(hzstring))pystring = ""For hzi = 1 To hzpysumhzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))Select Case hzpyhexCase &HB0A1 To &HB0C4: pystring = pystring + "A"Case &HB0C5 To &HB2C0: pystring = pystring + "B"Case &HB2C1 To &HB4ED: pystring = pystring + "C"Case &HB4EE To &HB6E9: pystring = pystring + "D"Case &HB6EA To &HB7A1: pystring = pystring + "E"Case &HB7A2 To &HB8C0: pystring = pystring + "F"Case &HB8C1 To &HB9FD: pystring = pystring + "G"Case &HB9FE To &HBBF6: pystring = pystring + "H"Case &HBBF7 To &HBFA5: pystring = pystring + "J"Case &HBFA6 To &HC0AB: pystring = pystring + "K"Case &HC0AC To &HC2E7: pystring = pystring + "L"Case &HC2E8 To &HC4C2: pystring = pystring + "M"Case &HC4C3 To &HC5B5: pystring = pystring + "N"Case &HC5B6 To &HC5BD: pystring = pystring + "O"Case &HC5BE To &HC6D9: pystring = pystring + "P"Case &HC6DA To &HC8BA: pystring = pystring + "Q"Case &HC8BB To &HC8F5: pystring = pystring + "R"Case &HC8F6 To &HCBF9: pystring = pystring + "S"Case &HCBFA To &HCDD9: pystring = pystring + "T"Case &HEDC5: pystring = pystring + "T"Case &HCDDA To &HCEF3: pystring = pystring + "W"Case &HCEF4 To &HD1B8: pystring = pystring + "X"Case &HD1B9 To &HD4D0: pystring = pystring + "Y"Case &HD4D1 To &HD7F9: pystring = pystring + "Z"Case Elsepystring = pystring + Mid(hzstring, hzi, 1)End SelectNexthztopy = pystringEnd Function方法二:VBA自定义函数"=getpy()"下面是一个VBA自定义函数,工具->宏->Visual Basic编辑器->,插入模块,在VBA编辑器里面->插入->模块->贴入上述代码,那么。
EXCEL如何提取汉字首字母
方法/步骤1.首先,打开Excel,同时按下Alt+F11键,打开VBE界面,如下图所示。
在VBE界面中,单击图片中所示的左上角空白处,选择“插入“,”模块“。
2.此时,就插入了一个模块,后面的代码就要放到这个模块中,保证右侧空白区域是模块代码的编辑区(最保险的做法是双击模块),然后执行下一步操作。
3.将下面的代码全部复制粘贴到空白区域。
Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy& pinyin(Mid(str, i, 1)) Next iEnd Function4.然后关闭这个新界面,返回Excel,就可以像Excel自带的函数一样使用这个自定义的Getpy函数了,它只有一个参数,参数可以直接指定单元格,也可以直接输入字符。
在excel中把汉字转换成拼音(只取首字母)
打开Excel->工具->宏->Viaual Basic编辑器在弹出来的窗口中对着VBAproject点右键->插入->模块下面会出现一个名为"模块1",点击在右边的空白栏中粘贴以下内容:Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy & pinyin(Mid(str, i, 1))Next iEnd Function********复制到此结束,本行不复制*******现在转换函数已编写完成!关掉此编缉的窗口。
EXCEL如何提取汉字首字母
方法/步骤1.首先,打开Excel,同时按下Alt+F11键,打开VBE界面,如下图所示。
在VBE界面中,单击图片中所示的左上角空白处,选择“插入“,”模块“。
2.此时,就插入了一个模块,后面的代码就要放到这个模块中,保证右侧空白区域是模块代码的编辑区(最保险的做法是双击模块),然后执行下一步操作。
3.将下面的代码全部复制粘贴到空白区域。
Function pinyin(p As String) As Stringi = Asc(p)Select Case iCase -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 = pEnd SelectEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy& pinyin(Mid(str, i, 1)) Next iEnd Function4.然后关闭这个新界面,返回Excel,就可以像Excel自带的函数一样使用这个自定义的Getpy函数了,它只有一个参数,参数可以直接指定单元格,也可以直接输入字符。
excel_汉字转换成拼音简拼(只取首字母)
名字转换为首字母(VBA自定义函数)1、打开EXCEL2、按 ALT+F11 ,点击插入-插入模块,在右面窗口中粘贴下面代码,直接关闭窗口3、输入公式=hztopy(A1),填充所有单元格4、选中所有缩写,复制-选择性粘贴-数值(因为是自定义函数,只有在当前文件中可以显示结果,其他电脑因没有公式而显示错误)5、使用条件格式,检索出含有汉字的单元格:先点中一个单元格(设为D5),条件格式-新建格式规则-使用公式确定要设置格式的单元格:在下面对话框中输入公式 =LENB(D5)>LEN(D5),自己设置格式,确定后退出,再把该单元格的格式用格式刷刷所有单元格。
有汉字的出现所设格式6、选择自定义排序-排序依据“单元格颜色”-次序“无单元格颜色”“在底端”-确定。
7、将汉字手动改写为相应的字母。
8、核对多音字。
注:以上方法只可以在当前文件夹使用,如何将宏保存,使自定义函数可以在所有文件夹中使用1、新建一个EXCEL2、按 ALT+F11 ,点击插入-插入模块,在右面窗口中粘贴下面代码,直接关闭窗口3、另存为-其他格式-文件名改为宏名称、保存类型选择“EXCEL加载宏(*,xlam)”,文件将自动保存在C:\Users\111\AppData\Roaming\Microsoft\AddIns文件夹。
4、打开需要工作的EXLEL,点击开始-EXCEL选项-加载项-转到(G)...-选中上面保存的宏名称-确定。
这样,在该电脑的所有EXCEL中,都可以直接使用自定义公式。
代码(只复制星号内的内容)******************************************************************************* Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As Integer, hzi As Integer, hzpyhex As Integerhzstring = Trim(hzpy)hzpysum = Len(Trim(hzstring))pystring = ""For hzi = 1 To hzpysumhzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))Select Case hzpyhexCase &HB0A1 To &HB0C4: pystring = pystring + "A"Case &HB0C5 To &HB2C0: pystring = pystring + "B"Case &HB2C1 To &HB4ED: pystring = pystring + "C"Case &HB4EE To &HB6E9: pystring = pystring + "D"Case &HB6EA To &HB7A1: pystring = pystring + "E"Case &HB7A2 To &HB8C0: pystring = pystring + "F"Case &HB8C1 To &HB9FD: pystring = pystring + "G"Case &HB9FE To &HBBF6: pystring = pystring + "H"Case &HBBF7 To &HBFA5: pystring = pystring + "J"Case &HBFA6 To &HC0AB: pystring = pystring + "K"Case &HC0AC To &HC2E7: pystring = pystring + "L"Case &HC2E8 To &HC4C2: pystring = pystring + "M"Case &HC4C3 To &HC5B5: pystring = pystring + "N"Case &HC5B6 To &HC5BD: pystring = pystring + "O"Case &HC5BE To &HC6D9: pystring = pystring + "P"Case &HC6DA To &HC8BA: pystring = pystring + "Q"Case &HC8BB To &HC8F5: pystring = pystring + "R"Case &HC8F6 To &HCBF9: pystring = pystring + "S"Case &HCBFA To &HCDD9: pystring = pystring + "T"Case &HEDC5: pystring = pystring + "T"Case &HCDDA To &HCEF3: pystring = pystring + "W"Case &HCEF4 To &HD1B8: pystring = pystring + "X"Case &HD1B9 To &HD4D0: pystring = pystring + "Y"Case &HD4D1 To &HD7F9: pystring = pystring + "Z"Case Elsepystring = pystring + Mid(hzstring, hzi, 1)End SelectNexthztopy = pystringEnd Function*******************************************************************************。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
方法一:VBA自定义函数"=hztopy()"下面是一个VBA自定义函数,工具->宏->Visual Basic编辑器->,插入模块,在VBA编辑器里面->插入->模块->贴入下述代码,(按ALT+F11,插入模块,在右面窗口中粘贴下面代码)那么,比如在A3中有"进退两难",则在B3中输入"=hztopy(A3)",则会得到"JTLN"。
不过此法有时候也会出错,比如"皓、鑫、婷、雯、奕"等,就无法提取汉字拼音首字母。
Function hztopy(hzpy As String) As StringDim hzstring As String, pystring As StringDim hzpysum As Integer, hzi As Integer, hzpyhex As Integerhzstring = Trim(hzpy)hzpysum = Len(Trim(hzstring))pystring = ""For hzi = 1 To hzpysumhzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))Select Case hzpyhexCase &HB0A1 To &HB0C4: pystring = pystring + "A"Case &HB0C5 To &HB2C0: pystring = pystring + "B"Case &HB2C1 To &HB4ED: pystring = pystring + "C"Case &HB4EE To &HB6E9: pystring = pystring + "D"Case &HB6EA To &HB7A1: pystring = pystring + "E"Case &HB7A2 To &HB8C0: pystring = pystring + "F"Case &HB8C1 To &HB9FD: pystring = pystring + "G"Case &HB9FE To &HBBF6: pystring = pystring + "H"Case &HBBF7 To &HBFA5: pystring = pystring + "J"Case &HBFA6 To &HC0AB: pystring = pystring + "K"Case &HC0AC To &HC2E7: pystring = pystring + "L"Case &HC2E8 To &HC4C2: pystring = pystring + "M"Case &HC4C3 To &HC5B5: pystring = pystring + "N"Case &HC5B6 To &HC5BD: pystring = pystring + "O"Case &HC5BE To &HC6D9: pystring = pystring + "P"Case &HC6DA To &HC8BA: pystring = pystring + "Q"Case &HC8BB To &HC8F5: pystring = pystring + "R"Case &HC8F6 To &HCBF9: pystring = pystring + "S"Case &HCBFA To &HCDD9: pystring = pystring + "T"Case &HEDC5: pystring = pystring + "T"Case &HCDDA To &HCEF3: pystring = pystring + "W"Case &HCEF4 To &HD1B8: pystring = pystring + "X"Case &HD1B9 To &HD4D0: pystring = pystring + "Y"Case &HD4D1 To &HD7F9: pystring = pystring + "Z"Case Elsepystring = pystring + Mid(hzstring, hzi, 1)End SelectNexthztopy = pystringEnd Function方法二:VBA自定义函数"=getpy()"下面是一个VBA自定义函数,工具->宏->Visual Basic编辑器->,插入模块,在VBA编辑器里面->插入->模块->贴入上述代码,那么。
那么,比如在A2中有"进退两难",则在B2中输入"=getpy(A2)",则会得到"JTLN"。
不过此法有时候也会出错,比如"鑫、雯、奕"等,就无法提取汉字拼音首字母,还有些字如"皓、婷"等被错提取为“Z”。
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 >= 53689 And tmp <= 54480) Thengetpychar = "Y"ElseIf (tmp >= 54481 And tmp <= 62289) Thengetpychar = "Z"Else '如果不是中文,则不处理getpychar = charEnd IfEnd FunctionFunction getpy(str)For i = 1 To Len(str)getpy = getpy & getpychar(Mid(str, i, 1))Next iEnd Function方法三:Excel函数LOOKUP这个函数在Excel里面最多只能设置自动提取字段的前四个字的拼音首字母,多了会提示公式太长。