I wrote a VBA code to input data, but it doesn't work for decimals

时间:2017-10-12 09:42:17

标签: excel vba excel-vba finance

So this is the code, which works only for integers

Dim CoupRate As Double
    Do
        CoupRate = InputBox("enter coupon rate in percent without % sign. It must be between 0.00% and 25.00%")
        If CoupRate < 0 Or CoupRate > 25 Then
            MsgBox ("CoupRate must be between 0% and 25%")
        Else
            Exit Do
        End If
    Loop

2 个答案:

答案 0 :(得分:1)

Please Use Comma , instead of dot .

答案 1 :(得分:0)

我也可以在输出中获得小数。你能否更具体一点。

    CoupRate = InputBox("enter coupon rate in percent without % sign. It must be between 0.00% and 25.00%")
    If CoupRate < 0 Or CoupRate > 25 Then
        MsgBox ("CoupRate must be between 0% and 25%")
    Else
        'Exit Do
        MsgBox CoupRate & "%"
    End If