excel怎么把多列内容合并到一列
时间:2023-04-02 17:19:23
先看一下原始数据,A到E列为单元格数据,需要将每行的非空单元格内容合并到F列存储在一个单元格中,并且用逗号分开。
选择【开发工具】-【插入】- 选择【ActiveX控件】中的按钮。
用鼠标在excel表格中画出一个按钮。
双击该按钮,进入编辑代码模式。
粘贴下列代码:
Private Sub CommandButton1_Click()
Dim n, i, j, m
Dim arr, brr()
n = [a65535].End(xlUp).Row
ReDim brr(1 To n)
arr = Range("A1:E" & n) '其中A1:EN表示的是原始数据区域
For i = 1 To n
For j = 1 To 5 '5表示A到E列是5列
If arr(i, j) <> "" Then
brr(i) = brr(i) & "," & arr(i, j)
End If
Next j
brr(i) = Mid(brr(i), 2, 99)
Next i
[F1].Resize(n, 1) = Application.Transpose(brr) 'F1表示从F1开始输出结果
End Sub
返回excel工作表界面,点击【开发工具】-【编辑模式】按钮退出编辑模式。
点击刚才插入的命令按钮,F列就输出了我们想要的内容。
注意:
只需要更改代码中加标注的原始区域列标和行号及输出结果位置的第一个单元格就可以应用到读者自己实际的工作表中去了。
标签:excel怎么把多列内容合并到一列
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Word怎么设置序号替换为上标
2022-02-07 11:58:21
![](https://img.aspxhome.com/file/2023/0/31880_0s.png)
如何隐藏Word中的文字的三个技巧介绍
2022-08-09 05:16:26
![](https://img.aspxhome.com/file/2023/3/29753_0s.jpg)
word中字符底色怎么设置
2022-01-29 20:55:48
word组织结构图怎么做?
2022-05-01 15:20:59
![](https://img.aspxhome.com/file/2023/7/34637_0s.gif)
如何在Mac上使用Word 2011的提示和工具?
2023-07-06 02:25:59
word开启文字识别功能的方法 word文档文字识别功能的使用方法教程
2022-05-17 11:35:27
![](https://img.aspxhome.com/file/2023/1/24111_0s.jpg)
Word如何快速选中所有红色字体
2023-10-09 02:55:09
![](https://img.aspxhome.com/file/2023/4/31764_0s.png)
Win10系统怎么看电脑使用了多长时间?Win10查看运行时间
2023-12-13 22:55:01
![](https://img.aspxhome.com/file/2023/3/51743_0s.jpg)
Word"替换"如何批量改排版格式
2023-11-27 13:22:37
![](https://img.aspxhome.com/file/2023/4/18194_0s.png)
word打印预览不全
2022-12-18 14:52:37
word如何设置图片透明度
2023-08-30 15:04:45
WIN10管理员阻止运行程序怎么办?WIN10管理员阻止运行程序的方法
2023-11-11 18:38:10
![](https://img.aspxhome.com/file/2023/7/47797_0s.png)
word 书名号怎么打出来
2022-12-20 19:40:50
![](https://img.aspxhome.com/file/2023/4/33194_0s.jpg)
Excel如何实现折线图分组
2023-10-02 00:04:13
![](https://img.aspxhome.com/file/2023/6/36246_0s.jpg)
Win10蓝牙键盘pin码如何输入?
2023-11-24 09:19:54
![](https://img.aspxhome.com/file/2023/2/50762_0s.jpg)
Win10频繁死机怎么办?Win10频繁假死解决办法
2023-11-13 03:44:08
![](https://img.aspxhome.com/file/2023/7/48997_0s.png)
牛逼!Word处理数据比Excel还快速~
2023-06-23 17:25:29
![](https://img.aspxhome.com/file/2023/9/24219_0s.png)
如何给Word中文字后添加读音(图文介绍)
2023-12-13 00:27:00
![](https://img.aspxhome.com/file/2023/9/21289_0s.jpg)
如何使用 iCloud.com 恢复最近删除的文件?
2023-11-28 21:38:03
![](https://img.aspxhome.com/file/2023/2/a194162_0s.png)
word总有一天会用上的查找和替换技巧
2022-04-15 15:31:40