跳到主要內容

如何在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)

然後,拖動填充手柄以將此公式應用於其他單元格,請參見屏幕截圖:

  • 保養竅門:
  • 在上面的公式中,您可以用其他分隔符替換“,”字符,例如 =TEXTJOIN("/",TRUE,A2:C2)
  • 要合併多個行中的單元格值,只需更改單元格引用,如下所示: =TEXTJOIN(",",TRUE,A2:A7)
  • 此TEXTJOIN還可以使用分隔符將一系列單元格組合為單個單元格,如下所示: =TEXTJOIN(",",TRUE,A2:C7)

使用指定的分隔符將單元格的行,列或範圍連接成一個單元格

Excel的Kutools 支持強大的功能-結合 這可以幫助您將基於行,列或一系列單元格的所有數據合併到一條記錄中,而不會丟失數據。 請參見下面的演示。    點擊下載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

尖端:在以上腳本中,“Function Combine(WorkRng As Range, Optional Sign As String = "~") As String“,分隔符”~指定了“”以分隔合併結果,您可以更改它以滿足您的需要。

3。 然後請輸入公式 =Combine(A2:C2) 在空白單元格中,然後將填充手柄拖動到要應用此公式的範圍內,該行中的所有單元格都將合併為帶有虛線的單元格。 看截圖:

保養竅門:使用上述用戶定義函數,您還可以根據列組合單元格值,只需輸入此公式 =Combine(A2:A7) 以獲得所需的合併數據。


使用公式將單元格的行或列連接到一個具有換行符的單元格中

有時,您可能需要使用換行符來分隔串聯的文本字符串,通常,CHAR(10)將返回換行符。 在這裡,您可以使用以下方法解決此任務:


方法A:使用串聯功能將帶有換行符的單元格合併

在這裡,您可以將串聯函數與Char(10)字符組合在一起,以得到合併結果,該結果以換行符分隔。

1。 請輸入或複制以下公式:

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

然後,將填充手柄向下拖動到要應用此公式的單元格上,您將得到以下結果:

2。 然後,您應該點擊 首頁 > 自動換行 格式化單元格,然後,您將根據需要獲得結果:

保養竅門:要合併多個行中的單元格值,只需更改單元格引用,如下所示: =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)

得到合併結果後,請記住將公式單元格設置為 自動換行,請參見屏幕截圖:

保養竅門:要合併多個行中的單元格值,只需更改單元格引用,如下所示: =TEXTJOIN(CHAR(10),TRUE,A2:A7)


通過使用出色的功能將行,列或單元格範圍連接到具有指定分隔符的一個單元格中

如果您對上述公式和代碼感到不滿意,請在這裡推荐一個有用的工具- Excel的Kutools,其 結合 功能,您可以按行,列或範圍將單元格值快速組合到一個單元格中。

提示:要應用此 結合 功能,首先,您應該下載 Excel的Kutools,然後快速輕鬆地應用該功能。

安裝後 Excel的Kutools,請這樣做:

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