我有两个专栏的excel。 ColA和ColB。
每个列中都有逗号分隔值。 我需要将ColA中的每个值映射到ColB中的每个值。
示例数据:
ColA ColB
A,B,C 4,5
E,F 6,8,3
预期产出
A 4
A 5
B 4
B 5
C 4
C 5
E 6
E 8
E 3
F 6
F 8
F 3
我可以用宏来做这件事吗?
答案 0 :(得分:0)
玩数组,我不知道数据应该在哪里结束,所以你必须玩,但应该让你开始。
Dim strTest As String, strArray() As String
Dim strTest2 As String, strArray2() As String
Dim intCount As Integer, intCount2 As Integer
Dim colCount As Integer, i As Integer
colCount = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To colCount
strTest = Cells(i, 1).Value
strArray = Split(strTest, ",")
strTest2 = Cells(i, 2).Value
strArray2 = Split(strTest, ",")
For intCount = LBound(strArray) To UBound(strArray)
For intCount2 = LBound(strArray2) To UBound(strArray2)
Debug.Print Trim(strArray(intCount) & "," & strArray2(intCount2))
Next
Next
Next i