我有一个excel文件,其中包含一个单元格中的应用程序列表,并针对相邻单元格中的应用程序使用多个分隔的用户名。我需要在一列中将用户从一个单元格拆分为多个单元格,同时为每个用户重复应用程序的名称
Current data looks something like this;
Column1 | Column 2
Application 1 | User1,User2,User3
Application 2 | User1,User2,User3
I want to get an output to be something like this;
Column 1 | Column 2
Application 1 | User 1
Application 1 | User 2
Application 1 | User 3
Application 2 | User 1
Application 2 | User 2
Application 2 | User 3
我一直在玩索引匹配,VBA等,但是失败了-我认为到目前为止我完成的任何代码都不重要
答案 0 :(得分:0)
这是一种超级简单的方法:
Sub Reorg()
Dim i As Long, N As Long, ap As String, arr, a
Dim k As Long
N = Cells(Rows.Count, "A").End(xlUp).Row
k = 1
For i = 1 To N
ap = Cells(i, 1).Value
arr = Split(Cells(i, 2).Value, ",")
For Each a In arr
Cells(k, 3).Value = ap
Cells(k, 4).Value = a
k = k + 1
Next a
Next i
End Sub
对于 A 和 B 列中的原始数据: