使用自定义函数快速连接Excel表格中多单元格数据的方法
时间:2023-12-17 11:41:18
字符串处理是函数的软肋,动不动就多层嵌套,数组公式,有些功能还无法实现,比如用连接符连接文本,用Excel函数几乎是无法做到的,有了VBA自定义函数,这一切将SO EASY!
下面就介绍一个简单的字符串处理函数:
函数名:MYSTR
作 用:用任意连接符连接文本
参数介绍: 第一参数:(必须)指定连接符,可以是文本常量,也可以是单元格引用。忽略空单元格。
第二参数:(必须)需要连接的文本或单元格区域。
第三、四等参数:(可选)同第二参数
效果展示:
创建自定义函数的方法:
新建一个EXCEL文档,只保留一个工作表,其余删除。
按ALT+F11,打开VBE编辑器,新建一个模块,把下面的自定义函数代码复制到模块中,关闭VBE编辑器。
PublicFunction mystr(ll, ParamArray x())
For Each r In x
If IsArray(r) Then
For Each rr In r
If rr <> ""Then mystr = mystr & ll & rr
Next
Else
mystr = mystr & ll & r
End If
Next
mystr = Mid$(mystr, 2, Len(mystr))
EndFunction
按F12【另存为】,文件保存类型选择“Excel加载宏”。它将自动存入ADDIN文件夹中。
然后从任意一个EXCEL文件的【开发工具】-【加载宏】中勾选所保存的宏文件名,确定。就可以在工作表中的随心所欲的使用自定义的合并文本函数啦,赶紧的,动手试试吧——
标签:函数,文本,自定义,连接,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
XP系统excel选择性粘贴怎么用?
2022-03-16 22:01:03
![](https://img.aspxhome.com/file/2023/3/a296888_0s.png)
excel表格时间求差的方法
2023-08-26 15:33:37
win10手机预览版怎么快速切换键盘输入法图文教程
2022-02-04 00:40:39
![](https://img.aspxhome.com/file/2023/28/a250848_0s.jpg)
如何显示wps工具栏
2023-03-22 06:26:05
【Win7精简版下载】目前最好用的Win7极限精简版下载
2022-10-11 21:34:16
![](https://img.aspxhome.com/file/2023/26/a227818_0s.jpg)
Word 2010如何分拣英文
2022-01-22 16:33:53
![](https://img.aspxhome.com/file/2023/7/22177_0s.jpg)
OS X Yosemite 独立安装U盘制作教程
2023-10-21 12:38:17
win7好还是win11好?win11比win7优势介绍
2023-01-22 15:30:17
![](https://img.aspxhome.com/file/2023/1/a272583_0s.jpg)
ppt图片怎么裁剪拉伸成彩条图? ppt图形裁剪并做背景图的技巧
2023-07-18 19:53:55
![](https://img.aspxhome.com/file/2023/10/a345359_0s.jpg )
Word西格码符号∑的录入
2023-04-13 21:41:04
![](https://img.aspxhome.com/file/2023/4/21414_0s.gif)
ppt文件很大该怎么办?PPT演示文稿的压缩方法
2023-07-30 00:39:46
![](https://img.aspxhome.com/file/2023/10/a347057_0s.jpg)
wps怎么给文字添加注释
2022-02-23 21:56:06
现阶段「携号转网」存在什么副作用?| 申请办理前需要注意什么?
2022-03-07 16:31:25
Win7屏幕刷新率如何更改?Win7屏幕刷新率更改的方法
2022-01-29 17:38:26
![](https://img.aspxhome.com/file/2023/26/a228382_0s.png)
Xftp怎么新建会话?Xftp新建会话的方法
2022-05-14 19:04:37
![](https://img.aspxhome.com/file/2023/7/a331054_0s.jpg)
Win7/win10如何打开445端口?445端口打开教程图解
2023-10-31 20:07:55
![](https://img.aspxhome.com/file/2023/28/a242090_0s.jpg)
外星人win10原版镜像下载_附外星人win10专业版安装教程
2022-09-16 12:06:43
![](https://img.aspxhome.com/file/2023/26/a222176_0s.png)
win10电源设置方法_win10电源使用常见问题汇总
2023-03-10 12:48:44
![](https://img.aspxhome.com/file/2023/4/a308161_0s.jpg)
迅雷自动续费怎么取消?怎么关闭迅雷会员自动续费?
2022-02-01 21:10:53
![](https://img.aspxhome.com/file/2023/6/a324275_0s.png)
电脑怎么设置定时关闭程序?
2023-04-17 01:10:36
![](https://img.aspxhome.com/file/2023/6/a322592_0s.png)