跳到主要内容

如何在Excel中将逗号分隔的值拆分为行或列?

在某些情况下,您可能需要将以逗号分隔的选定单元格的值拆分为行或列。 在这里,我们将为您详细介绍三种解决此问题的方法。

使用文本到列功能将逗号分隔的值拆分为列
用VBA代码将逗号分隔的值分成几行
使用 Kutools for Excel 快速将逗号分隔值拆分为行或列


使用文本到列功能将逗号分隔的值拆分为列

您可以应用“文本到列”功能将所选单元格的逗号分隔值拆分为列。 请执行以下操作。

1.选择您想要将值拆分为列的单元格范围,然后单击 时间 > 文本到列。 看截图:

2.在第一 将文本转换为列向导 对话框中,选择 分隔 选项,然后单击 下一页 按钮。

3.在第二 将文本转换为列向导 对话框中,仅选中 逗号定界符 部分,然后单击 下一页 按钮。

4.最后 将文本转换为列向导 对话框中选择一个单元格以在 目的地 框,最后单击 完成 按钮。 看截图:

现在,所选单元格中所有用逗号分隔的值将拆分为不同的列,如下所示。

通常情况下, 文字至栏 此功能仅将单元格拆分为单独的列,如果要将单元格拆分为行,该怎么办?
在这里, Kutools for Excel's 分裂细胞 实用程序可以帮助您快速将单元格按空格,逗号,换行符,其他分隔符或特定宽度拆分为Excel中的单独行和列。 立即下载 Kutools for Excel! (30 天免费试用)


用VBA代码将逗号分隔的值分成几行

要将逗号分隔的值拆分为行,可以应用以下VBA代码。

1。 按 其他 + F11 同时打开 Microsoft Visual Basic应用程序 窗口。

2.在 Microsoft Visual Basic应用程序 窗口中,单击 插页 > 模块。 然后将下面的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 键来运行代码。 在弹出 Kutools for Excel 对话框中,选择要拆分的单元格,然后单击 OK 按钮。

4.在第二个弹出窗口中 Kutools for Excel 对话框中,选择一个单元格以查找拆分值,然后单击 OK.

然后,您可以看到所选单元格中用逗号分隔的值分成几行,如下所示。


使用 Kutools for Excel 快速将逗号分隔值拆分为行或列

The 分裂细胞 实用程序 Kutools for Excel 可以帮助您轻松地将逗号分隔的值拆分为行或列。

1.选择您需要拆分的单元格,然后单击 库工具 > 合并与拆分 > 分裂细胞。 看截图:

2.在 分裂细胞 对话框中选择 拆分为行 or 拆分为列 ,在 Type 根据需要。 而在 指定分隔符 部分,选择 其他名称 选项,在文本框中输入逗号,然后单击 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 Tab 为 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