使用VBA将Sheet1中的(固定范围)迭代列复制到Sheet2中的列范围

使用VBA将Sheet1中的(固定范围)迭代列复制到Sheet2中的列范围,vba,excel,Vba,Excel,我在Sheet1(AG6:AG25)中有一系列数字,其中包含RAND()函数,我希望通过将转置的值粘贴到Sheet2中的每一次迭代的新行上,来迭代每一次迭代的结果 解决方法如下: Sub MonteCarlo() Dim transposedVariant As Variant Dim sourceRowRange As Range Dim sourceRowRangeVariant As Variant Dim rangeFilledWithTransposedData As Range D

我在Sheet1(AG6:AG25)中有一系列数字,其中包含
RAND()
函数,我希望通过将转置的值粘贴到Sheet2中的每一次迭代的新行上,来迭代每一次迭代的结果

解决方法如下:

Sub MonteCarlo()

Dim transposedVariant As Variant
Dim sourceRowRange As Range
Dim sourceRowRangeVariant As Variant
Dim rangeFilledWithTransposedData As Range
Dim i As Long

Application.ScreenUpdating = False

For i = 1 To 5000

    Set sourceRowRange = Sheets("Sheet1").Range("AG6:AG25")
    sourceRowRangeVariant = sourceRowRange.Value
    transposedVariant = Application.Transpose(sourceRowRangeVariant)

    Set rangeFilledWithTransposedData = Sheets("Sheet2").Range("A" & i & ":T" & i)
    rangeFilledWithTransposedData.Value = transposedVariant

Next i

Application.ScreenUpdating = True

End Sub

请找到密码。我希望它能帮助你

子模拟()

我想我会坚持多久

Dim j尽可能长

对于i=1到1000

For j = 1 To 20

'Calculate


    Sheet1.Cells(j, 1) = Application.WorksheetFunction.RandBetween(100, 150) * 1


Next j
接下来我


结束子步骤

第3步您尝试了什么?请出示你的密码。如果我们看不到你做了什么,我们就无法判断你做错了什么以及如何纠正请注意,这里有大约100个关于如何在堆栈上查找最后使用的行/列的问题。请在问题本身中添加一个示例。您好,两位,很抱歉没有给出示例,因为它无法编译。我已经找到了一个完整的解决方案,除了一个语法我不知道。请参阅更新:)@Chris您从哪里得到错误,哪些错误?您不能转置值
应用程序。转置(sourceRowRangeVariant)
而是转置范围
应用程序。转置(sourceRowRange)
这是如何回答OPs问题的?他已经在执行Rand函数,他想知道如何在每次Rand重新计算后复制sheet1中的范围并粘贴到Sheet2中的第一个空列中。您的代码只会一次又一次地将随机数放入范围为(A1:A20)的Sheet1中。