【问题标题】:Convert data in one column to two columns将一列中的数据转换为两列
【发布时间】:2015-07-12 02:15:00
【问题描述】:

我有here所见的数据。

数据仅排列在一列中。每个唯一 ID 主要有两组数据(可能缺少一个或两个数据集),每个条目由波浪号(例如~)字符分隔。该工作表还显示了所需的输出。

是否有可用于获得所需输出的 ​​VB 代码或表格公式?主文档大约有 132,300 行。我还没想出一个逻辑。

【问题讨论】:

    标签: vba excel multiple-columns


    【解决方案1】:

    这应该会相当快地处理您的数据。

    Sub foo_on_doo_too()
        Dim v As Long, vDOOs As Variant, vRSLTs As Variant
    
        With ActiveSheet   '<- set this worksheet reference properly!
            vDOOs = .Range(.Cells(4, 1), .Cells(Rows.Count, 1).End(xlUp)).Value2
            ReDim vRSLTs(1 To 2, 1 To Int(UBound(vDOOs, 1) / 4))
    
            For v = LBound(vDOOs, 1) To UBound(vDOOs, 1) Step 4
                vRSLTs(1, Int(v / 4) + 1) = vDOOs(v, 1)
                vRSLTs(2, Int(v / 4) + 1) = vDOOs(v + 2, 1)
            Next v
    
            .Cells(4, 3).Resize(UBound(vRSLTs, 2), 2) = _
                Application.Transpose(vRSLTs)
        End With
    End Sub
    

    建议您将 ActiveSheet 引用设置为像 Sheets("Sheet1") 这样的明确引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多