我有以下数据集:
A B
Bob black, brown, blue
Jane red, yellow
Mary orange
我想获得输出:
A B
Bob black
Bob brown
Bob blue
Jane red
Jane yellow
Mary orange
或者,不必重复A列中的名称。我的猜测是,我需要将行转置为列,但是为了增加数据的排列,我陷入了添加其他行的麻烦。
任何帮助将不胜感激。
答案 0 :(得分:1)
这是在VBA中执行此操作的方法:
Dim lastRow As Integer, rng As Range
With Sheet1 ' <-- Use the appropriate worksheet.
lastRow = .Range("B" & .Rows.Count).End(xlUp).Row
For i = lastRow To 1 Step -1
Set rng = .Range("B" & i)
Dim items() As String
items = Split(rng.Value, ",")
rng.Value = items(0)
For j = 1 To UBound(items)
.Rows(i + j).Insert
rng.Offset(j).Value = Trim$(items(j))
'rng.Offset(j, -1).Value = rng.Offset(0, -1).Value ' <-- Optional
Next j
Next i
End With