跳到主要內容

如何在Excel中將逗號分隔的值拆分為行或列?

在某些情況下,您可能需要將以逗號分隔的選定單元格的值拆分為行或列。 在這裡,我們將為您詳細介紹三種解決此問題的方法。

使用文本到列功能將逗號分隔的值拆分為列
用VBA代碼將逗號分隔的值分成幾行
使用Kutools for Excel將逗號分隔的值快速拆分為行或列


使用文本到列功能將逗號分隔的值拆分為列

您可以應用“文本到列”功能將所選單元格的逗號分隔值拆分為列。 請執行以下操作。

1.選擇您想要將值拆分為列的單元格範圍,然後單擊 數據 > 文本到列。 看截圖:

2.在第一 將文本轉換為列嚮導 對話框中,選擇 分隔 選項,然後單擊 下一頁 按鈕。

3.在第二 將文本轉換為列嚮導 對話框中,僅選中 逗號 盒子裡 定界符 部分,然後單擊 下一頁 按鈕。

4.最後 將文本轉換為列嚮導 對話框中選擇一個單元格以在 目的地 框,最後單擊 按鈕。 看截圖:

現在,所選單元格中所有用逗號分隔的值將拆分為不同的列,如下所示。

通常情況下, 文字至欄 此功能僅將單元格拆分為單獨的列,如果要將單元格拆分為行,該怎麼辦?
在這裡, Excel的Kutools's 分裂細胞 實用程序可以幫助您快速將單元格按空格,逗號,換行符,其他分隔符或特定寬度拆分為Excel中的單獨行和列。 立即下載 Kutools for Excel! (30 天免費試用)


用VBA代碼將逗號分隔的值分成幾行

要將逗號分隔的值拆分為行,可以應用以下VBA代碼。

1。 按 其他 + F11 同時打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊。 然後將下面的VBA代碼複製並粘貼到“模塊”窗口中。

VBA代碼:將逗號分隔的值拆分為行

Sub SplitAll()
	Dim xRg As Range
	Dim xRg1 As Range
	Dim xCell As Range
	Dim I As Long
	Dim xAddress As String
	Dim xUpdate As Boolean
	Dim xRet As Variant
	On Error Resume Next
	xAddress = Application.ActiveWindow.RangeSelection.Address
	Set xRg  = Application.InputBox("Please select a range", "Kutools for Excel", xAddress, , , , , 8)
	Set xRg  = Application.Intersect(xRg, xRg.Worksheet.UsedRange)
	If xRg Is Nothing Then Exit Sub
		If xRg.Columns.Count > 1 Then
			MsgBox "You can't select multiple columns", , "Kutools for Excel"
			Exit Sub
			End If
			Set xRg1 = Application.InputBox("Split to (single cell):", "Kutools for Excel", , , , , , 8)
			Set xRg1 = xRg1.Range("A1")
			If xRg1 Is Nothing Then Exit Sub
				xUpdate = Application.ScreenUpdating
				Application.ScreenUpdating = False
				For Each xCell In xRg
					xRet = Split(xCell.Value, ",")
					xRg1.Worksheet.Range(xRg1.Offset(I, 0), xRg1.Offset(I + UBound(xRet, 1), 0)) = Application.WorksheetFunction.Transpose(xRet)
					I = I + UBound(xRet, 1) + 1
				Next
				Application.ScreenUpdating = xUpdate
			End Sub

3。 按 F5 鍵來運行代碼。 在彈出 Excel的Kutools 對話框中,選擇要拆分的單元格,然後單擊 OK 按鈕。

4.在第二個彈出窗口中 Excel的Kutools 對話框中,選擇一個單元格以查找拆分值,然後單擊 OK.

然後,您可以看到所選單元格中用逗號分隔的值分成幾行,如下所示。


使用Kutools for Excel將逗號分隔的值快速拆分為行或列

The 分裂細胞 的效用 Excel的Kutools 可以幫助您輕鬆地將逗號分隔的值拆分為行或列。

1.選擇您需要拆分的單元格,然後單擊 庫工具 > 合併與拆分 > 分裂細胞。 看截圖:

2。 在裡面 分裂細胞 對話框中選擇 拆分為行 or 拆分為列 ,在 類別 根據需要。 而在 指定分隔符 部分,選擇 其他 選項,在文本框中輸入逗號,然後單擊 OK 按鈕。 看截圖:

3。然後會彈出另一個提示框,提醒您選擇一個單元格以輸出結果,請參見屏幕截圖:

4。 點擊 OK 按鈕,您可以看到如下屏幕截圖所示的結果。

拆分為列

拆分為行

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


演示:使用Kutools for Excel快速將逗號分隔的值拆分為行或列

最佳辦公生產力工具

🤖 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 (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
A jak zmienić kod żeby nie pytał o ustawienie się w A1 i potem aby wynik był np też od A1 w dół
This comment was minimized by the moderator on the site
Hi Bartek,
You mean don't want to pop up the second dialog to select the target cell, and want to specify the target cell in the code directly?
If so, you need to change the following lines.
For example, you need to start outputting results from B1 and automatically fill down.
Please change this line:
Set xRg1 = Application.InputBox("Split to (single cell):", "Kutools for Excel", , , , , , 8)
to
Set xRg1 = Application.Range("B2")
And then remove the next line:
Set xRg1 = xRg1.Range("A1")
This comment was minimized by the moderator on the site
i still cant upload my csv into 365
This comment was minimized by the moderator on the site
Go to excel file Data option -> text to column->delimited -> Done
it will spit comma separated value into individual column
example
id name add
1 Ratnesh myAdd
2,Yog,myAdd
we will apply in the 2nd record it will split record like 1st records,
Thanks,
Ratnesh Sahu
This comment was minimized by the moderator on the site
Go to excel file Data option -> text to column->delimited -> Done
it will spit comma separated value into individual column
example

id name add

1 Ratnesh myAdd

2,Yog,myAdd


we will apply in the 2nd record it will split record like 1st records,


Thanks,
Ratnesh Sahu
This comment was minimized by the moderator on the site
Thanks it helped :)
This comment was minimized by the moderator on the site
This is amazing, thanks for making it free and easy to use!
This comment was minimized by the moderator on the site
Thank you!
This comment was minimized by the moderator on the site
Alternately for separating into rows, use the text to column steps and then copy & paste ->transpose to turn the columns into rows.
This comment was minimized by the moderator on the site
Thanks Jake! This is what I was looking for. :)
This comment was minimized by the moderator on the site
Good one, the utility help me a lot. Thanks for that... :)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations