简体   繁体   中英

VBA Excel - Need to copy a range, paste it in a column then loop

I have a long column of words, need to copy and paste the first 30 or so into a column on another sheet, then paste the next 30 in the following column, etc.

I recorded the start of a macro, but have no idea how to make it do the whole thing without writing each bit out individually.

Sub asdasd()

'
    Range("A2:A29").Select
    Selection.Copy
    Sheets("COMMON WORDS").Select
    Range("AG2").Select
    ActiveSheet.Paste
    Sheets("COMMON - SINGLE LIST").Select
    Range("A30").Select
    Range("A30,A57").Select
    Range("A57").Activate
    Range("A30:A57").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("COMMON WORDS").Select
    Range("AH2").Select
    ActiveSheet.Paste
End Sub
Sub LoopCopy()

    Dim rngCopy As Range, rngPaste As Range

    Set rngCopy = Sheets("COMMON - SINGLE LIST").Range("A2:A29")
    Set rngPaste = Sheets("COMMON WORDS").Range("AG2")

    'copy while there's data in rngCopy...
    Do while application.counta(rngCopy) > 0
        rngCopy.copy rngPaste
        set rngCopy = rngCopy.offset(rngCopy.rows.count, 0) '<< move copy range           
        set rngPaste = rngPaste.offset(0, 1) '<< move paste postion over
    Loop

 End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM