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

时间:2018-05-28 06:31:35

标签: excel vba excel-vba

我在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

1 个答案:

答案 0 :(得分:-1)

请找到代码。我希望它会对你有所帮助。

子模拟()

Dim i As Long

Dim j As Long

对于i = 1到1000

For j = 1 To 20

'Calculate


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


Next j

接下来我

End Sub