跳到主要内容

如何在Excel中将多个单元格与空格,逗号或其他分隔符组合成一个单元格?

当您将多个列或行中的单元格合并为一个单元格时,合并后的数据可能不会被分隔。 但是,如果要用指定的标记(例如空格,逗号,分号或其他标记)将它们分开,该怎么办? 本教程将为您介绍一些方法。


使用公式将单元格的行或列连接到一个带有空格,逗号或其他分隔符的单元格中

在Excel中,您可以使用以下公式将一行单元格或一列单元格合并为一个单元格。


方法A:使用“&”运算符合并单元格

在Excel中,您可以使用“&”运算符来组合不同的文本字符串或单元格值。

请输入以下公式以将单元格分成多列:(用空格分隔合并的结果,您可以根据需要用其他分隔符替换空白。)

=A2&" "&B2&" "&C2

然后,将填充手柄向下拖动到要应用此公式的单元格上,并且来自不同列的数据已合并到一个单元格中,请参见屏幕截图:

  • 提示:
  • 在上面的公式中,您可以用其他分隔符替换&运算符之间的空格,例如 =A2&"-"&B2&"-"&C2
  • 如果您需要合并多个行中的单元格值,则只需更改单元格引用,如下所示: =A2&" "&A3&" "&A4&" "&A5&" "&A6&" "&A7

方法B:使用串联功能合并单元格

Excel中的连接功能还用于将多个文本字符串或单元格值连接到一个单元格中。

请输入以下公式或将其复制到空白单元格中:

=CONCATENATE(A2, "-", B2, "-", C2)

然后,将填充手柄向下拖动到要应用此公式的单元格上,您将得到以下结果:

  • 提示:
  • 在上面的公式中,您可以将“-”字符替换为其他分隔符,例如 =CONCATENATE(A2, ";", B2, ";", C2)
  • 如果您需要合并多个行中的单元格值,则只需更改单元格引用,如下所示: =CONCATENATE(A2, "-", A3, "-", A4, "-", A5, "-", A6, "-", A7)

方法C:使用Textjoin函数合并单元格

如果您具有Excel 365和更高版本,则有一个新功能-Textjoin,此功能还可以帮助您将多个单元格合并为一个单元格。

输入以下公式或将其复制到空白单元格中:

=TEXTJOIN(",",TRUE,A2:C2)

然后,拖动填充手柄以将此公式应用于其他单元格,请参见屏幕截图:

  • Tips:
  • 在上面的公式中,您可以用其他分隔符替换“,”字符,例如 =TEXTJOIN("/",TRUE,A2:C2)
  • 要合并多个行中的单元格值,只需更改单元格引用,如下所示: =TEXTJOIN(",",TRUE,A2:A7)
  • 此TEXTJOIN还可以使用分隔符将一系列单元格组合为单个单元格,如下所示: =TEXTJOIN(",",TRUE,A2:C7)

使用指定的分隔符将单元格的行,列或范围合并为一个单元格

Kutools for Excel 支持强大的功能-结合 这可以帮助您将基于行,列或单元格范围的所有数据合并到一条记录中,而不会丢失数据。 请参见下面的演示。    点击下载Kutools for Excel!


通过用户定义的功能将单元格的行或列连接到一个具有空格,逗号或其他分隔符的单元格中

在Excel中,您还可以创建用户定义函数,以将行或列的单元格合并为带有空格或指定标记的单个单元格。

1。 保持 ALT + F11 键盘上的按键打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将VBA复制到模块中。

VBA:将基于行或列的单元格合并为一个带有特定分隔符的单元格:

Function Combine(WorkRng As Range, Optional Sign As String = "~") As String
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
    If Rng.Text <> " " Then
        OutStr = OutStr & Rng.Text & Sign
    End If
Next
Combine = Left(OutStr, Len(OutStr) - 1)
End Function

Tips::在以上脚本中,“Function Combine(WorkRng As Range, Optional Sign As String = "~") As String“,分隔符”~指定了“”以分开合并的结果,您可以更改它以满足您的需要。

3。 然后请输入公式 =Combine(A2:C2) 在空白单元格中,然后将填充手柄拖到要应用此公式的范围内,该行中的所有单元格都将合并为带有虚线的单元格。 看截图:

Tips:使用上述用户定义函数,您还可以根据列组合单元格值,只需输入此公式 =Combine(A2:A7) 以获得所需的合并数据。


使用公式将单元格的行或列连接到一个具有换行符的单元格中

有时,您可能需要使用换行符来分隔串联的文本字符串,通常,CHAR(10)将返回换行符。 在这里,您可以使用以下方法解决此任务:


方法A:使用串联功能将带有换行符的单元格合并

在这里,您可以将连接函数与Char(10)字符组合在一起,以获得合并结果,该合并结果由换行符分隔。

1。 请输入或复制以下公式:

=CONCATENATE(A2,CHAR(10),B2,CHAR(10),C2)

然后,将填充手柄向下拖动到要应用此公式的单元格上,您将得到以下结果:

2。 然后,您应该点击 主页 > 自动换行 格式化单元格,然后,您将根据需要获得结果:

Tips:要合并多个行中的单元格值,只需更改单元格引用,如下所示: =CONCATENATE(A2,CHAR(10),A3,CHAR(10),A4,CHAR(10),A5,CHAR(10),A6,CHAR(10),A7)


方法B:使用Textjoin函数将带有换行符的单元格组合在一起(Excel 365和更高版本)

如果需要组合多个单元,则上面的公式可能有点困难,因此,Textjoin函数可以快速轻松地处理此任务。

请输入以下公式或将其复制到空白单元格中:

=TEXTJOIN(CHAR(10),TRUE,A2:C2)

得到合并结果后,请记住将公式单元格设置为 自动换行,请参见屏幕截图:

Tips:要合并多个行中的单元格值,只需更改单元格引用,如下所示: =TEXTJOIN(CHAR(10),TRUE,A2:A7)


通过使用出色的功能将行,列或单元格范围连接到具有指定分隔符的一个单元格中

如果您对以上公式和代码感到不满意,请在这里推荐一个有用的工具- Kutools for Excel,其 结合 功能,您可以按行,列或范围将单元格值快速组合到一个单元格中。

提示:申请这个 结合 功能,首先,您应该下载 Kutools for Excel,然后快速轻松地应用该功能。

安装后 Kutools for Excel,请这样做:

1。 选择要合并到单元格中的范围单元格值。

2。 请单击以应用此功能 库工具 > 合并与拆分合并行,列或单元格而不会丢失数据。 看截图:

doc用逗号将数据合并9 1

3。 在弹出的对话框中,请指定所需的操作,如下图所示:

4。 然后,点击 Ok,您将获得如下屏幕截图所示的结果:

1)。 将每一行的单元格值合并为一个单元格:

2)。 将每一列的单元格值合并为一个单元格:

3)。 将一系列单元格值合并为一个单元格:

点击下载Kutools for Excel并立即免费试用!


更相关的结合行和列的文章:

  • 合并和合并行而不丢失Excel中的数据
  • 如果您应用“合并和居中”命令(“对齐”面板上的“主页”选项卡>合并和居中)命令来合并Excel中的数据行,则Excel仅将数据保留在最左上角的单元格中。 用户必须使用另一种方法将多行数据合并为一行而不删除数据。
  • 合并重复的行并求和Excel中的值
  • 在Excel中,当您具有一系列包含某些重复项的数据时,您可能总是会遇到此问题,现在您想要合并重复数据并在另一列中求和相应的值,如下面的屏幕快照所示。 您如何解决这个问题?
  • 串联的单元格忽略或跳过Excel中的空白
  • Excel的串联功能可以帮助您将多个单元格值快速组合到一个单元格中,如果所选单元格中有一些空白单元格,则此功能也将合并空白。 但是,有时候,您只想将单元格与数据连接起来并跳过空单元格,如何在Excel中完成呢?

  • 超级公式栏 (轻松编辑多行文本和公式); 阅读视图 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 和保存数据; 拆分单元格内容; 合并重复的行和总和/平均值...防止细胞重复; 比较范围...
  • 选择重复或唯一 行; 选择空白行 (所有单元格都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择...
  • 确切的副本 多个单元格,无需更改公式参考; 自动创建参考 到多张纸; 插入项目符号,复选框等...
  • 收藏并快速插入公式,范围,图表和图片; 加密单元 带密码 创建邮件列表 并发送电子邮件...
  • 提取文字,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级筛选 (将过滤方案保存并应用于其他工作表); 高级排序 按月/周/日,频率及更多; 特殊过滤器 用粗体,斜体...
  • 结合工作簿和工作表; 根据关键列合并表; 将数据分割成多个工作表; 批量转换xls,xlsx和PDF...
  • 数据透视表分组依据 周号,周几等 显示未锁定的单元格 用不同的颜色 突出显示具有公式/名称的单元格...
kte选项卡201905
  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部
Comments (34)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I would like to know if I have a list of people with their information in different cells in one column but different row how to combine them in one cell For e,g I have one person teaching English, math and science and his name is repeated in one column but the courses are in different rows so I want to combine all the courses in one cell for that teacher. if I have 50 teachers I need to have all the courses that the teacher is teaching in one cell.
This comment was minimized by the moderator on the site
Hi, Lavina,
Do you mean to combine multiple cell values in a column based on duplicate names in another column as below screenshot shown:

You can insert a screenshot to make your problem more intuitive.
This comment was minimized by the moderator on the site
This is exactly what I'm looking for. Is this problem solved?
This comment was minimized by the moderator on the site
Hi, Piotr,
To solve this problem, maybe the following article can help you, please check it:
https://www.extendoffice.com/documents/excel/2723-excel-concatenate-based-on-criteria.html
This comment was minimized by the moderator on the site
VBA doesn't work for me, excel 2016.
This comment was minimized by the moderator on the site
Working on trying to get your VBA code to work however I keep getting a #NAME? error. How do I fix this? I've used this code before and it worked wonderfully but now it gives me an error.
This comment was minimized by the moderator on the site
But it is not working for large data. I have around 50000 rows to combine in single cell.
This comment was minimized by the moderator on the site
415xxe 5687sdc sa4567 415xxe 5687sdc sa4567 415xxe 5687sdc sa4567 415xxe 5687sdc sa4567 I need to separate these in different columns and then put a comma behind the last column
This comment was minimized by the moderator on the site
The VBA code does not work I get an error Microsoft Visual Basic for Applications - Compile error: Syntax error then the line "If Rng.Text "," Then" is highlighted in blue and on the top highlighted in yellow it says this "function combine(workrng as range, optional sign as string = ",") as string I am using excel 2016 on a pc
This comment was minimized by the moderator on the site
I genuinely enjoy studying on this website, it holds good content. Never fight an inanimate object. by P. J. O'Rourke. dfdkbafbadfkagdd
This comment was minimized by the moderator on the site
how to combine 2 cell with space in between with 2 independent cell format. Eg. If one cell is Red digits & other cell has digits in green, it should combine with Red & green digits.
This comment was minimized by the moderator on the site
The VBA code worked really well thanks. My only issue is that it is including blanks so that my combined output ends up looking like this: "test, test, , , , , , test" How could I get it to exclude blank cells within the range?
This comment was minimized by the moderator on the site
If you found the answer let me now please as well.
This comment was minimized by the moderator on the site
instead of the line in the original code:

If Rng.Text <> ", " Then
OutStr = OutStr & Rng.Text & Sign


you need to add a "test" to determine if the cell is empty followed by the statement above which adds the delimiter. Delete the above 2 lines and then Copy the following code in and your COMBINE function will remove the blanks from your list.

If IsEmpty(Rng.Value) = True Then

OutStr = OutStr & ""

ElseIf Rng.Text <> ", " Then

OutStr = OutStr & Rng.Text & Sign
This comment was minimized by the moderator on the site
The VBA macro worked very well after I adjusted for the my cell locations and I was able to add a space after the comma for a better display of the data.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations