跳到主要內容

如何將數據從列轉置為Excel中的單個單元格?

當您需要將數據列表轉置到工作表中的單個單元格中時,通常可以應用 CONCATENATE 函數可以將單元格列表合併為一個單元格,但是,如果需要合併大量數據,將很複雜。 本文,我將討論一些快速技巧,供您解決Excel中的此任務。

使用用戶定義函數將數據從列轉置到一個單元格中

使用Kutools for Excel將列中的數據轉換為一個單元格


除了合併功能以合併單元格值列表之外,您可以應用以下VBA代碼以盡快獲得結果。

1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。

VBA代碼:將列中的數據轉置為一個單元格

Function transposeRange(Rg As Range)
'updateby Extendoffice
    Dim xCell As Range
    Dim xStr As String
    For Each xCell In Rg
        If Not IsEmpty(xCell.Value) Then
            xStr = xStr & xCell.Value & ","
        End If
    Next
    transposeRange = Left(xStr, Len(xStr) - 1)
End Function

3。 然後保存並關閉此代碼,返回工作表,然後輸入以下公式: = transposerange(A1:A10) 放入空白單元格以放入結果,然後按 Enter 鍵,您將獲得列中的所有單元格值都位於單個單元格中,請參見屏幕截圖:

doc將細胞轉置為一個細胞1

備註:在上面的代碼中, A1:A10 是您要轉置為一個單元格的列表範圍,而且,您可以通過僅更改腳本中的逗號來將合併的內容與其他定界符(例如逗號,破折號,空格等)分開。 xStr = xStr&xCell.Value&“,”.


如果你有 Excel的Kutools,其功能強大的工具-結合,您可以將列,行或範圍中的數據合併到一個單元格中。

Excel的Kutools : 帶有300多個便捷的Excel加載項,可以在30天內免費試用.

安裝後 Excel的Kutools,請執行以下操作: 立即免費下載Kutools for Excel! )

1。 選擇要合併到一個單元格中的數據列。

2。 點擊 庫工具 > 合併與拆分合併行,列或單元格而不會丟失數據,請參見屏幕截圖:

3。 在彈出的對話框中,選擇 合併成單個單元格根據以下選項合併選定的單元格,然後指定分隔符以分隔合併的內容,請參見屏幕截圖:

doc將細胞轉置為一個細胞3

4。 然後點擊 Ok or 登記 按鈕,您將根據需要獲得以下結果:

doc將細胞轉置為一個細胞4 2 doc將細胞轉置為一個細胞5

立即下載和免費試用Excel的Kutools!


Excel的Kutools:具有300多個方便的Excel加載項,可以在30天內免費試用,沒有任何限制。 立即下載並免費試用!

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Would anybody know how to add a conditional rule to this function? Basically I have an e-mail directory for multiple businesses. There is a column where I list either Yes or No in response to whether the E-mail is the business' main contact. I am hoping adjust the code so that only the main contacts are pulled and listed in one cell. Therefore, the condition would be that the Main Contact Column lists Yes. I have tried using if statements but I am fairly new to all of this. Any help would be much appreciated!
This comment was minimized by the moderator on the site
Hello friend,
Glad to help. Please read this article: https://www.extendoffice.com/documents/excel/2706-excel-vlookup-return-multiple-values-in-one-cell.html. I believe it can solve your problem. Have a nice day.

Sincerely,
Mandy
This comment was minimized by the moderator on the site
This has been ridiculously helpful to me a number of times. Thank you so much!
This comment was minimized by the moderator on the site
Hi,

Thanks a lot! I'm using your following function and it works very well. I would like to include an "if" function in the transposerange. What should I add to the function in VBA? Basically, it would work like a countif. So we would read the formula =transposerangeif(range,criteria).

Thanks in advance!

Function transposeRange(Rg As Range)
'updateby Extendoffice 20151207
Dim xCell As Range
Dim xStr As String
For Each xCell In Rg
If Not IsEmpty(xCell.Value) Then
xStr = xStr & xCell.Value & ","
End If
Next
transposeRange = Left(xStr, Len(xStr) - 1)
End Function
This comment was minimized by the moderator on the site
Hello,Sophie,
Could you give an example for your need, you can insert a screenshot here.
This comment was minimized by the moderator on the site
Thanks, this was very helpful.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations