我在excel中有一个用逗号分隔的列(,)
column
cell1: 1,2,3
cell2: 2,4
我想拆分每个单元格,使值显示在垂直单元格中,以便每个单元格转换为
cell1 => split into 3 vertical cells containing values 1,2,3
cell2 => split into 2 vertical cells containing values 2,4
我发现了很多方法可以横向完成这项工作,但是在垂直细胞上挣扎。
答案 0 :(得分:1)
从以下数据开始:
首先选择您要处理的数据并运行此宏:
Sub Vertical()
Dim i As Long, st As String
i = 1
Dim startP As Range
For Each r In Selection
If i = 1 Then
st = r.Text
i = 2
Else
st = st & "," & r.Text
End If
Next r
Set startP = Selection(1, 2)
ary = Split(st, ",")
i = 1
For Each a In ary
startP(i, 1).Value = a
i = i + 1
Next a
End Sub
生产:
修改#1:强>
要将每个单元格从水平显示的逗号分隔列表转换为垂直间隔的逗号分隔列表,请运行此宏:
Sub Vertical2()
Dim r As Range
For Each r In Selection
r.Value = Replace(r.Value, ",", "," & vbCrLf)
r.WrapText = True
Next r
End Sub
在选定的单元格上:
答案 1 :(得分:-1)