|
I think if your use formula to express the result will easier for you to trace the problem
Private Sub CommandButton1_Click()
Dim 购买总股数 As Double
Dim 购买时股价 As Double
Dim 收益率 As Double
Dim 请选择股市类型 As Integer
Dim 计算结果
If TextBox1.Value = "" Then
MsgBox "请在购买总股数中输入购买总股数"
TextBox1.SetFocus
Exit Sub
Else
购买总股数 = Val(TextBox1.Value)
End If
If TextBox2.Value = "" Then
MsgBox "请在购买时股价中输入购买股价"
TextBox2.SetFocus
Exit Sub
Else
购买时股价 = Val(TextBox2.Value)
End If
If TextBox3.Value = "" Then
MsgBox "请在收益率中输入目标收益率"
TextBox3.SetFocus
Exit Sub
Else
收益率 = Val(TextBox3.Value)
End If
Sheets("目标股价").Select
Cells(3, 4) = 购买时股价
Cells(4, 4) = 购买总股数
Cells(13, 4) = 收益率
If OptionButton1.Value = True Then
Cells(15, 4) = "沪市"
Else
If OptionButton2.Value = True Then
Cells(15, 4) = "深市"
End If
End If
If OptionButton1.Value = True And 购买总股数 * 购买总估价 > 1667 Then
计算结果 = "((" & 购买时股价 & " * " & 购买总股数 & "* 1.003 + 1) * (1 + " & 收益率 & " ) + 1) / (" & 购买总股数 & " * 0.996)"
'计算结果 = ((购买时股价 * 购买总股数 * 1.003 + 1) * (1 + 收益率) + 1) / (购买总股数 * 0.996)
Else
If OptionButton1.Value = True And 购买总股数 * 购买总估价 <= 1667 Then
计算结果 = "((" & 收益率 & " * ( " & 购买时股价 & " *" & 购买总股数 & " + 6)) + 12) / (0.999 * " & 购买总股数 & " )"
Else
If OptionButton2.Value = True And 购买总股数 * 购买总估价 > 1667 Then
计算结果 = "(( " & 购买时股价 & "* 1.003) * (1 + " & 收益率 & " )) / (" & 购买总股数 & "* 0.996)"
Else
If OptionButton2.Value = True And 购买总股数 * 购买总估价 <= 1667 Then
计算结果 = "((" & 收益率 & "* (" & 购买时股价 & "* " & 购买总股数 & "+ 5)) + 10) / (0.999 * " & 购买总股数 & ")"
End If
End If
End If
End If
Cells(16, 4).Formula = "=" & 计算结果
End Sub |
|