excel 自定义函数实现提取汉字
时间:2022-03-15 15:09:48
从字符串中提取或者删除汉字是在我们日常使用Excel中时常遇到的问题,这里提供一个从网络上收集而来的提取或者删除汉字的自定义函数,方便大家日常使用。
'---------------------------------------------------
'功能:提取字符串中汉字或者非汉字
'说明:Rg原字符串或单元格
'Et为True时,提取汉字,否则为提取非汉字
'发布:http://www.office26.com
'---------------------------------------------------
FunctionExtractHanzi(RgAsVariant,_
OptionalEtAsBoolean=True)AsString
WithCreateObject("VBSCRIPT.REGEXP")
.Global=True
IfEtThen
.Pattern="[^u4e00-u9fa5]"
Else
.Pattern="[u4e00-u9fa5]"
EndIf
ExtractHanzi=.Replace(Rg,"")
EndWith
EndFunction
实际应用:
作为一个函数使用在工作表的公式中,如:单元格A1的值为"ExcelFans.com欢迎你",然后我们在A2中键入公式=ExtractHanzi(A1),显示结果为:欢迎你:
把它用到其他的代码中,以下代码就是去除所选定区域中的所有汉字
'---------------------------------------------------
'功能:删除选定区域中所有汉字
'发布:http://www.office26.com
'---------------------------------------------------
SubDelAllHanzi()
DimRgAsRange,Rg1AsRange
DimxAddressAsString
OnErrorResumeNext
xAddress=ActiveSheet.UsedRange.Address
SetRg=Application.InputBox("请选择一个区域:","office26.com",xAddress,,,,,8)
IfRgIsNothingThenExitSub
SetRg=Application.Intersect(Rg,ActiveSheet.UsedRange)
IfRgIsNothingThenExitSub
ForEachRg1InRg
Rg1=ExtractHanzi(Rg1,False)
Next
EndSub
excel 自定义函数实现提取汉字的下载地址:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win10 1909怎么退出安全模式?Win10 1909安全模式退出方法简述
![](https://img.aspxhome.com/file/2023/8/48778_0s.jpg)
掌握 Word 中的两个高效操作技巧,按时下班靠自己
![](https://img.aspxhome.com/file/2023/5/17115_0s.png)
word单元格怎么设置调整列宽行高但是不影响相邻列?
![](https://img.aspxhome.com/file/2023/8/22878_0s.png)
WPS表格中给数据添加一个三维效果边框
![](https://img.aspxhome.com/file/2023/7/53547_0s.jpg)
怎么把excel2007两个工作表垂直
Excel中进行文字边框与底纹的操作方法
word怎样设置图片格式不同
Excel 2019快速移动或复制工作表的4种方法
![](https://img.aspxhome.com/file/2023/5/a141115_0s.jpg)
如何使用Microsoft Word制作邀请函
![](https://img.aspxhome.com/file/2023/0/23810_0s.jpg)
Excel2007 批注添加.删除.打印批注
![](https://img.aspxhome.com/file/2023/2/39312_0s.jpg)
GridView数据复制到Excel中文乱码怎么办?
![](https://img.aspxhome.com/file/2023/7/42627_0s.jpg)
Win10专业版怎么打开本地组策略编辑器?
![](https://img.aspxhome.com/file/2023/4/50384_0s.png)
服务没有及时响应启动或控制请求的解决办法(含Win10、Win7)
![](https://img.aspxhome.com/file/2023/8/53338_0s.jpg)
word字竖着怎么打
![](https://img.aspxhome.com/file/2023/0/35750_0s.png)
word表格两列互换
![](https://img.aspxhome.com/file/2023/9/34729_0s.gif)
Word英文单词排版断行的技巧
![](https://img.aspxhome.com/file/2023/7/19547_0s.png)
清除excel宏病毒 如何清除excel电子表格宏病毒
word怎么去掉横线?word删除横线方法介绍
![](https://img.aspxhome.com/file/2023/8/23248_0s.png)
iOS 14信息应用中的“提到”功能使用方法
![](https://img.aspxhome.com/file/2023/3/a194223_0s.jpg)
如何在Word 2013中调整行和段落空间?
![](https://img.aspxhome.com/file/2023/3/23293_0s.jpg)