|
楼主 |
发表于 2009-5-20 11:10
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Private A() As Double
Private Sub GetNum(ByVal B As Double, E As Double, ByVal n%)
If n <= 2 Then Exit Sub
ReDim A(1 To n)
Dim i%, j%, S As Double, T As Double
S = 0
For i = 2 To n
A(i) = Rnd
S = S + A(i)
Next
For i = 2 To n - 1
For j = i + 1 To n
If A(j) > A(i) Then
T = A(i)
A(i) = A(j)
A(j) = T
End If
Next
Next
For i = 2 To n - 1
A(i) = A(i) / S
Next
A(1) = B
S = E - B
For i = 2 To n - 1
A(i) = Round(A(i - 1) + A(i) * S, 3)
Next
A(n) = E
End Sub
Sub Test()
Application.ScreenUpdating = False
Dim i%, n%
n = 11
GetNum 10, 0, n
For i = 2 To n + 1
Cells(i, 1) = i - 1
Cells(i, 2) = A(i - 1)
If i >= 3 Then Cells(i, 3) = A(i - 2) - A(i - 1)
Next
For i = 3 To n
Cells(i, 4) = Cells(i, 3) - Cells(i + 1, 3)
Next
Application.ScreenUpdating = True
End Sub |
|