2017-06-20 103 views
0

我在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 
+0

你看過'Split()'嗎? –

+0

@AlexP現在看這個:https://www.techonthenet.com/excel/formulas/split.php但是,我不希望它以這種格式返回。 – taa06

回答

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 

我已經在處理了對羣體雖然注意補充,這是假定在列項的所有值是一致的。

0

嘗試是這樣的

Sub ArrayToRows() 
'Declare your array or arrays 


'Array1 would correspond to your "Column A" array, I'm not sure of the names you want, _ 
'just change the variables to suit your needs 

For i = LBound(Array) to UBound(Array) 
    Cells(1,1).Value = Array1(i) & " " & Array2(i) & " " & Array3(i) 
Next i 

End Sub