Excel利用自定义函数提取字符串中的重复字符
时间:2022-02-16 10:51:25
有时需要将Excel单元格内字符串中的重复字符提取出来,例如提取字符串“abcdeAbcDe”中重复的几个字符“bce”,如图所示,可以用自定义函数实现。
1.按Alt+F11,打开VBA编辑器。
2.单击菜单“插入→模块”,在代码窗口中粘贴代码:
Function GetDupChar(theString As String) As String
Dim i As Integer
For i = 1 To Len(theString) – 1
If Len(theString) – Len(Replace(theString, Mid(theString, i, 1), "")) > 1 Then ‘
If InStr(GetDupChar, Mid(theString, i, 1)) = 0 Then GetDupChar = GetDupChar & Mid(theString, i, 1)
End If
Next
End Function
3.关闭VBA编辑器,返回Excel工作表界面。
假如字符串在A2单元格,在B2输入公式:
=GetDupChar(A2)
要将多个单元格中的字符串合并后提取重复字符,如A3单元格为“12345123”,A4单元格为“mnc12526”,在B8单元格输入公式:
=GetDupChar(A3&A4)
将返回这两个单元格中字符串合并后重复的字符“1235”。
标签:单元格,字符,字符串,重复,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何在Excel中同时查看多个已定义名称的区域
2023-07-26 04:41:02
![](https://img.aspxhome.com/file/2023/8/a156668_0s.jpg)
批量修改WPS或excel表格一行或一列数据
2022-05-17 17:10:16
word表格中添加行或列的方法图解步骤
2022-02-11 01:35:50
CUMIPMT函数计算给定期间累计应偿还的利息总额
2022-11-15 17:30:19
利用 excel 删除重复项和Vlookup函数组合 给不连续的产品进行批量编号
2022-06-08 23:47:02
![](https://img.aspxhome.com/file/2023/6/a155516_0s.jpg)
excel给单元格添加说明,不需要备注,可以用批注功能
2022-03-20 12:38:34
![](https://img.aspxhome.com/file/2023/2/a140552_0s.jpg)
excel超过15位数字如何处理
2023-02-08 03:15:11
![](https://img.aspxhome.com/file/2023/0/a140200_0s.png)
Word 2007:修改图片尺寸的三种方式
2022-08-09 01:47:55
![](https://img.aspxhome.com/file/2023/7/25067_0s.jpg)
Excel的50个逆天功能,动画教程珍藏版!看完变Excel绝顶高手
2023-01-08 08:04:57
![](https://img.aspxhome.com/file/2023/9/42829_0s.gif)
Word功能区不见了怎么让其自动隐藏显示或永久显示
2023-11-30 02:52:23
![](https://img.aspxhome.com/file/2023/4/18774_0s.jpg)
如何隐藏Word的表格边框
2023-11-29 05:38:09
![](https://img.aspxhome.com/file/2023/9/18289_0s.jpg)
什么是Word智能标记,Word智能标记怎么设置和取消
2023-04-08 17:36:08
![](https://img.aspxhome.com/file/2023/1/34011_0s.jpg)
word2016中让文字快速对齐的两种方法
2022-12-02 02:41:31
![](https://img.aspxhome.com/file/2023/3/25283_0s.png)
word 默认字体是什么
2022-07-07 15:47:12
![](https://img.aspxhome.com/file/2023/8/33238_0s.png)
怎么让excel表格首行或首列固定不动?
2022-07-04 14:29:21
转发周知!工作最实用Word快捷键
2023-11-11 11:19:47
![](https://img.aspxhome.com/file/2023/2/17102_0s.jpg)
Word2003如何避免表格下一页断行 Word2003实现表格下一页不断行方法
2023-04-19 16:09:59
![](https://img.aspxhome.com/file/2023/2/25482_0s.png)
如何在Word 2013中对图片进行基本编辑?
2023-05-02 15:41:57
![](https://img.aspxhome.com/file/2023/1/23251_0s.jpg)
Excel中进行怎么插入日期选择器
2022-03-11 18:48:10
如何设置word表格居中表格列宽为3厘米
2022-01-29 02:41:38
![](https://img.aspxhome.com/file/2023/4/35714_0s.png)