|
没有理解楼主代码的实际意义
建议:既然使用数组就不要使用公式了,这60秒大多数用在了写公式上了,下面代码对公式理解的可能不对,请参考:
Sub 按钮2_Click()
Dim OutData(), TestRows As Long, i As Long
Dim OutArea As String, t0
t0 = Timer
ActiveSheet.UsedRange.Offset(99, 0).ClearContents
TestRows = [i1].Value
If TestRows <= 0 Then TestRows = 10000
If TestRows > Row_Limit Then TestRows = Row_Limit
[i1].Value = TestRows
OutArea = "B100:C" & TestRows
ReDim OutData(1 To TestRows - 99, 1 To 2)
OutData(1, 1) = Int((2000 * Rnd) + 1)
OutData(1, 2) = [C99]
If Rnd > 0.33 Then OutData(1, 2) = OutData(1, 2) + 1
For i = 2 To TestRows - 99
OutData(i, 1) = Int((2000 * Rnd) + 1)
If Rnd > 0.33 Then OutData(i, 2) = OutData(i - 1, 2) + 1 Else OutData(i, 2) = OutData(i - 1, 2)
Next i
Range(OutArea).Formula = OutData
[i2].Value = Timer - t0
End Sub |
|