【问题标题】:Map comma seperated values in two columns in Excel在 Excel 中的两列中映射逗号分隔值
【发布时间】:2016-11-10 14:53:44
【问题描述】:

我有一个包含两列的 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

我可以用宏来做到这一点吗?

【问题讨论】:

  • 是的,这可以用 vba 完成。在回答您的后续问题时,Stack Overflow 不是我服务的代码,也不是指向正确方向的站点。请自行尝试并在代码不起作用时返回代码,我们将帮助您解决具体问题。

标签: excel macros


【解决方案1】:

玩一下数组,我不知道数据应该在哪里结束,所以你必须玩弄,但应该让你开始。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2014-01-14
    • 2018-03-01
    • 1970-01-01
    相关资源
    最近更新 更多