Hi Experts, I'm a novice at VBA and am trying some simple code to generate some random numbers, store the results in an array and then output them on another sheet. Not sure if it's not recalculating each time or if it's the way I'm outputting the results but I get 100 columns of identical numbers instead of 100 columns of "random" numbers. Would appreciate any help! Here is the code:
Option Explicit
Option Base 1
Sub myMacro2()
Dim vData As Variant
Dim dOutput() As Variant
Dim j As Long
Dim k As Long
Application.ScreenUpdating = False
'Application.Calculation = xlCalculationManual
' Assign the range to a variant containing an array.
vData = Worksheets("Input2").Range("B2:B21")
' Set up the result array.
ReDim dOutput(UBound(vData, 1), 100)
' Generate the numbers.
For k = 1 To 100
With Worksheets("Input2")
.EnableCalculation = False
.EnableCalculation = True
.Calculate
End With
dOutput = vData
Next k
' Return results by assigning the result array to the range.
Worksheets("Results2").Range("B2"). _
Resize(UBound(dOutput, 1), 100) = dOutput
'Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
Bookmarks