我是VBA的新手,我想写下一段简单的代码,用于实现二项分布产品的双重求和。我写的代码是:
Sub reactiveTransshipment()
Dim i As Integer
i = 0
Dim j As Integer
j = 0
Dim y1 As Integer
y1 = 1037
Dim y2 As Integer
y2 = 1037
Dim PI1 As Double
PI1 = 0
Dim PI1_1 As Double
PI1_1 = 0
Dim PI1_2 As Double
PI1_2 = 0
Dim k1 As Double
Dim k2 As Double
Dim n As Integer
n = 2000
Dim P As Double
P = 0.5
For j = 0 To (y2 - 1)
For i = (y1 + 1) To (y1 + y2 - j)
k1 = WorksheetFunction.BinomDist(i, n, P, False)
k2 = WorksheetFunction.BinomDist(j, n, P, False)
PI1_2 = PI1_2 + (k1 * k2)
Next i
Next j
Worksheets(2).Range("D2").Value = k1
End Sub