简体   繁体   中英

Copy/Paste Special loop in VBA

Very new to VBA and trying to do a simply copy/paste special loop. How would you write the code so that each time it loops it copies one cell down in the Filter Out Pitchers tab and pastes special one cell down in the Batter Comparison tab?

Sub Hitters()

    For i = 1 To 500
        Worksheets("Filter Out Pitchers").Range("B2").Copy
        Worksheets("Batter Analysis").Paste _
        Destination:=Worksheets("Batter Analysis").Range("B1")
        Worksheets("Batter Analysis").Range("A88:AA88").Copy
        Worksheets("Batter Comparison").Range("A2:AA2").PasteSpecial xlPasteValues
    Next i
End Sub

Not sure I understood completely, but this may be what you're after:

For i = 1 To 500
    Worksheets("Filter Out Pitchers").Range("B" & (1+i)).Copy _
        Destination:=Worksheets("Batter Analysis").Range("B2")
    Worksheets("Batter Comparison").Range("A" & (1+i) & ":AA" & (1+i)).Value = _
        Worksheets("Batter Analysis").Range("A88:AA88").Value
Next i

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