excel自定义函数获取多个单元格中相同的字符
时间:2022-03-27 16:42:58
要在Excel中获取区域内各单元格字符串中的相同字符,可用下面的自定义函数。例如要在D1单元格获取A1:C1区域各单元格中相同的字符,如图:
按Alt+F11,打开VBA编辑器,单击菜单“插入→模块”,在代码窗口中输入自定义函数:
Function GetDupChars(rRng As Range) As String
Application.Volatile
Dim i As Integer, j As Integer, k As Integer
Dim Str As String
Str = rRng.Item(1).Text
For i = 1 To Len(Str)
k = 0
For j = 2 To rRng.Cells.Count
If InStr(rRng.Item(j).Text, Mid(Str, i, 1)) Then k = k + 1
Next
If k = j – 2 And InStr(GetDupChars, Mid(Str, i, 1)) = 0 _
Then GetDupChars = GetDupChars & Mid(Str, i, 1)
Next
End Function
然后关闭VBA编辑器,在D1单元格中输入公式即可:
=GetDupChars(A1:C1)
标签:函数,单元格,自定义,要在,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Excel表格怎么制作创意的柱形图?
2022-02-25 17:24:45
![](https://img.aspxhome.com/file/2023/1/40231_0s.png)
Excel 调用其他工作簿中的自定义颜色设置
2023-05-07 05:39:41
![](https://img.aspxhome.com/file/2023/8/a156558_0s.jpg)
驱动精灵把清理隐私加入右键菜单教程
2023-06-13 13:35:04
![](https://img.aspxhome.com/file/2023/0/53210_0s.png)
word2007将一个形状更改为另一个形状
2023-12-05 17:22:11
![](https://img.aspxhome.com/file/2023/2/19782_0s.jpg)
Excel使用XNPV函数计算不定期收益项目的净现值
2022-11-04 12:59:11
宽带连接提示651错误?宽带连接651错误解决教程
2023-11-07 09:26:03
![](https://img.aspxhome.com/file/2023/4/47904_0s.png)
wordpress怎样设置导航菜单
2022-03-09 04:01:35
word 如何输入版权符号的四种方法和各软件输入版权符号的通用方法
2022-11-08 23:11:13
如何更改word2007的smartart图形的样式
2023-11-30 00:22:36
excel2016怎么开启浮动工具栏
2023-05-01 08:28:20
![](https://img.aspxhome.com/file/2023/1/a142921_0s.jpg)
excel如何实现在转置表格的过程中消除对数据的影响?
2022-05-17 02:02:46
![](https://img.aspxhome.com/file/2023/8/41028_0s.jpg)
excel表格如何提取单元格数字
2022-06-25 20:58:16
Excel2007中最常用的技巧大全
2023-06-28 04:13:37
如何学习数据挖掘?
2023-04-07 07:52:10
在Word2010中根据现有内容新建Word文档
2023-12-13 14:39:28
![](https://img.aspxhome.com/file/2023/5/21595_0s.jpg)
word2007文档页码居中怎么设置
2023-02-08 02:41:01
Excel表格怎样多行合并居中
2022-01-17 13:13:23
![](https://img.aspxhome.com/file/2023/3/a153753_0s.png)
excel表格数据怎么制作柏拉图?
2023-12-07 00:09:17
![](https://img.aspxhome.com/file/2023/4/a141814_0s.jpg)
手机上的QQ邮箱如何添加word文档?
2023-11-29 04:23:28
Word中复制粘贴文本的精妙方法
2023-05-13 23:44:57
![](https://img.aspxhome.com/file/2023/6/24876_0s.jpg)