简体   繁体   English

VBA复制粘贴循环

[英]vba copy paste loop

I want to copy paste data with a loop, it might be very simple, however I cannot find the right way to do it, the following range I would like solve with a loop till row 13944: 我想用一个循环复制粘贴数据,这可能很简单,但是我找不到正确的方法,下面是我想用循环解决的以下范围,直到第13944行:

Range("A40:I52").Cut Range("J27")
Range("A40+26:I52+26").Cut Range("J27+26")

Range("A92:I104").Cut Range("J79")
Range("A118:I130").Cut Range("J105")
Range("A144:I156").Cut Range("J131")
Range("A170:I182").Cut Range("J157")
Range("A196:I208").Cut Range("J183")
Range("A222:I234").Cut Range("J209")
'+26 in all cases
'till 13944
Dim i as long

for i=79 to 13944 step 26
    Range(cells(i+13,1),cells(i+25,9)).cut cells(i,10)
next i

EDIT: 编辑:

Both in the original question and in the additional question below the key is to find a preferably simple algorithm for building the running indices. 在原始问题和下面的其他问题中,关键都是要找到一种优选的简单算法来构建运行指标。 In the 2nd question we need either 2 separate indices or 1 with more calculations, like 在第二个问题中,我们需要2个单独的索引或1个具有更多计算的索引,例如

2 indices: 2个指标:

Dim i as long, k as long
Dim shSrc as worksheet, shTrg as worksheet

Set shSrc=Worksheets("CME")
Set shTrg=Worksheets("RME")

k=2
For i=2 to ??? step 10
    shSrc.range(cells(i,10), cells(i+8,10)).copy 
    shTrg.cells(k,2).PasteSpecial Transpose:=True 
    k=k+1
next

1 index: 1个索引:

for i=2 to ???
    shSrc.range(cells(i+(i-2)*10,10), cells(i+(i-2)*10+8,10)).copy 
    shTrg.cells(i,2).PasteSpecial Transpose:=True 
next

(I think it's better using 2 indices :)) Please note how I reduced the need of typing by using vars for sheet references. (我认为使用2个索引会更好:))请注意,我如何通过使用vars作为工作表引用来减少打字的需要。

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

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