Copy/Paste Special loop in VBA

雨燕双飞 提交于 2020-06-29 11:47:49

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/41580980/copy-paste-special-loop-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!