Excel VBA中引用公式单元格
工作表中B11和B12里面分别是公式,B11=EXP(B5*SQRT(B10)),B12==EXP(-B5*SQRT(B10)),在VBA中引用这两个单元格时,u=Ran...
工作表中B11和B12里面分别是公式,
B11=EXP(B5*SQRT(B10)),B12==EXP(-B5*SQRT(B10)),
在VBA中引用这两个单元格时,
u = Range("B11")
d = Range("B12")
返回值却都是1,是哪出错了?应该怎么改?
Sub BinomialTrees()
Dim i As Integer, j As Integer
Dim u As Long, d As Long, p As Long
Dim S(1 To 5, 1 To 5) As Long, V(1 To 5, 1 To 5) As Long
'S(i,j):标的资产在第i个节点第j高的价格,V(i,j):相应期权的价值。
S(1, 1) = Worksheets("Sheet1").Range("B2").Value
u = Range("B11")
d = Range("B12")
For i = 1 To 5
For j = 1 To i
S(i, j) = S(1, 1) * (u ^ (i - j)) * (d ^ (j - 1))
Worksheets("Sheet1").Cells(50 - 2 * (i - 1) + 4 * (j - 1), 5 + 2 * (i - 1)).Value = S(i, j)
Next j
Next i
End Sub 展开
B11=EXP(B5*SQRT(B10)),B12==EXP(-B5*SQRT(B10)),
在VBA中引用这两个单元格时,
u = Range("B11")
d = Range("B12")
返回值却都是1,是哪出错了?应该怎么改?
Sub BinomialTrees()
Dim i As Integer, j As Integer
Dim u As Long, d As Long, p As Long
Dim S(1 To 5, 1 To 5) As Long, V(1 To 5, 1 To 5) As Long
'S(i,j):标的资产在第i个节点第j高的价格,V(i,j):相应期权的价值。
S(1, 1) = Worksheets("Sheet1").Range("B2").Value
u = Range("B11")
d = Range("B12")
For i = 1 To 5
For j = 1 To i
S(i, j) = S(1, 1) * (u ^ (i - j)) * (d ^ (j - 1))
Worksheets("Sheet1").Cells(50 - 2 * (i - 1) + 4 * (j - 1), 5 + 2 * (i - 1)).Value = S(i, j)
Next j
Next i
End Sub 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询