我想多次复制和转置一个范围,并寻找最快的方法来执行此操作。写了不同的方式,两者都很慢。它们看起来像这样:
...
For i = 1 To nrofSims
simNr = i
Application.Calculate
Range(Sim.Range("Res3Top").Offset(1, 0), Sim.Range("Res3Top").Offset(simMonths, 0)).Copy
Res3.Range("A4").Offset(i, 1).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Next i
...
和
...
For i = 1 To nrofSims
simNr = i
Application.Calculate
For j = 1 To simMonths
Res3.Range("A4").Offset(i, j) = Sim.Range("Res3Top").Offset(j, 0).Value
Next j
Next i
...
是否可以执行rangePaste.value = rangeCopy.value
之类的操作并转置矢量?
修改
更改为以下代码而不是更快。但是,正如评论中所写,我可能需要改变模型现在的工作方式。
...
Dim res3Sim As Range, res3Store As Range
Set res3Sim = Range(Sim.Range("Res3Top").Offset(1, 0), Sim.Range("Res3Top").Offset(simMonths, 0))
Set res3Store = Range(Res3.Range("A4"), Res3.Range("A4").Offset(0, simMonths - 1))
Dim i As Integer
For i = 1 To nrofSims
simNr = i
Application.Calculate
res3Store.Offset(i, 1).Value2 = Application.Transpose(res3Sim.Value2)
Next i
...