2016-11-10 79 views
0

我有兩列的excel。 ColA和ColB。在Excel的兩列中映射逗號分隔的值

每列中都有逗號分隔的值。 我需要將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 

我能做到這一點與宏?

+2

是的,這可以用vba完成。在回答你的後續問題時,Stack Overflow不是對我服務的代碼,也不是我在正確方向的站點。請自行嘗試,並在代碼不起作用時返回代碼,我們將幫助您解決特定問題。 –

回答

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