Excel vba / Macro将行移至N行后的下一列并复制标题

时间:2018-08-24 23:52:49

标签: excel vba excel-vba

如何在excel vba / macro中使用命令按钮将第15(n)行之后的行移动/剪切到下一列,并重复我的标题列。 我有这样的数据: enter image description here

我想使用命令按钮将行(n)更改为列,结果如下: enter image description here

1 个答案:

答案 0 :(得分:1)

尝试一下。

Sub test()
    Dim vDB, rngDB As Range
    Dim vHead
    Dim rngT As Range, i As Long

    Set rngDB = Range("a3").CurrentRegion
    vHead = Range("a3").Resize(1, 2)
    For i = 16 To rngDB.Rows.Count Step 15
        vDB = rngDB.Range("a" & i).Resize(15, 2)
        Set rngT = Cells(3, Columns.Count).End(xlToLeft).Offset(, 1)
        rngT.Resize(1, 2) = vHead
        rngT.Offset(1, 0).Resize(15, 2) = vDB
    Next i
    rngDB.Offset(16).Clear
    Set rngDB = Range("a3").CurrentRegion
    rngDB.Borders.LineStyle = xlContinuous
End Sub