将数组拆分为多行

时间:2017-06-20 15:05:49

标签: excel excel-vba csv split vba

我在excel中有多个单元格,由70个点组成。如何将数组中的每个数字拆分成自己的行?

例如,目前我有一个数组:

A栏:

[(42.07, -86.03), (42.074092, -87.031812000000002)]

B栏:

[0.00e+00,9.06e+02]

C栏:

[1.69e+01,1.72e+00]

所有这些数组都在同一行。但是,我希望它以两个单独的行显示:

(42.07, -86.03)  |0.00e+00    |1.69e+01

(42.074092, -87.031812000000002) |9.06e+02    |1.72e+00

2 个答案:

答案 0 :(得分:0)

尝试这样的事情

import {ApiClient} from '@core/http'

答案 1 :(得分:0)

正如@AlexP所说,Split函数就是你想要的,你可以将结果数组输出到工作表

Sub ExpandToRows()

    Dim ColumnList As String, col As Variant, c As Range
    Dim OutputArray() As String, i As Long

    'list of columns to process
    ColumnList = "A,B,C" 'change to suit

    With Sheet1 'change to suit

        For Each col In Split(ColumnList, ",")

            Set c = .Cells(1, col) 'assume row 1, change to suit

            'determine if pair group
            If InStr(c.Value, "), (") > 0 Then

                'replace delimiter
                c.Value = Replace(c.Value, "), (", ")~(")

                'create array of values
                OutputArray = Split(c.Value, "~")

            Else '...or single values

                'create array of values
                OutputArray = Split(c.Value, ",")

            End If

            'write OutputArray to worksheet
            c.Resize(UBound(OutputArray) + 1) = Application.Transpose(OutputArray)

        Next col

    End With

End Sub

我已经添加了对配对组的处理,但请注意,这假设列条目中的所有值都是一致的。