每第6列之后的新行优秀

时间:2013-03-08 13:16:15

标签: excel

我有连续的数据。让我们A1到XFD1,我想分裂我的 每第6列的数据。这意味着A1-F1原样,从G1-L1应该转移到A2-F2,依此类推。

示例:

A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F A B C D E F 

我需要这样:

A B C D E F 
A B C D E F
A B C D E F
A B C D E F

1 个答案:

答案 0 :(得分:0)

此VBA例程将起作用。

Sub SplitData()
    Dim data As Range, arr() As Variant
    Dim row As Integer, i As Integer, j As Integer

    Set data = Range(Range("A1"), Range("A1").End(xlToRight))
    arr = data
    data.ClearContents

    row = 1

    On Error Resume Next
    For i = 1 To data.Columns.Count Step 6
        For j = 0 To 5
            Cells(row, j + 1) = arr(1, i + j)
        Next j
        row = row + 1
    Next i
End Sub