繁体   English   中英

复制并粘贴VBA Excel

[英]Copy and paste VBA excel

Sub Test()

Dim x As Integer

For x = 1 To 1000

Sheets("Test1").Range(Cells(x, 1), Cells(x, 10)).Select
Sheets("Test2").Cells(5, 16).PasteSpecial Paste:=xlValues, Transpose:=True

Next

End Sub

这是我的宏,此宏的用途,将工作表测试1中的范围“ Ax:Jx”复制到工作表测试2中的范围“ P5:P14”

注意:我想运行1000场景以查看对某些结果的影响。 因此,第一步,如上所示,我为方案创建了循环宏。

我被困在“ Sheets(” Test1“)。Range(Cells(i,1)&Cells(i,10))。Select”上。 如何定义此范围,使其可以像x循环一样循环。

无需选择或复制/粘贴:

Sub Test()

    Dim x As Integer, sht1, sht2

    Set sht1 = Sheets("Test1")
    Set sht2 = Sheets("Test2")

    For x = 1 To 1000

        sht2.Cells(5, 16).Resize(10, 1).Value = _
              Application.Transpose(sht1.Cells(x, 1).Resize(1, 10).Value)

    Next

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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