编写一个宏来粘贴第26行的范围

时间:2012-07-06 05:01:44

标签: excel excel-vba vba

我正在复制一个数组(Sheet1!A2:A831)并希望将其粘贴到Sheet2上!从A1开始的每26排。

我正在使用这个宏,但我遇到了一些麻烦:

Sub test()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("Sheet1!A2:A831").Copy
For i = 26 To LR Step 26
    Range("A" & i).PasteSpecial Paste:=xlPasteFormulas
Next i
End Sub

1 个答案:

答案 0 :(得分:0)

这是你在尝试的吗?

Sub test()
    Dim LR As Long, i As Long, n As Long

    With Sheets("Sheet1")
        LR = .Range("A" & .Rows.Count).End(xlUp).Row

        n = 1

        For i = 2 To LR 'A2:A831
            .Range("A" & i).Copy
            Sheets("Sheet2").Range("A" & n).PasteSpecial _
            Paste:=xlPasteFormulas

            n = n + 25
        Next i
    End With
End Sub