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

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

Upvotes: 0

Views: 94

Answers (2)

nishit dey
nishit dey

Reputation: 458

I was able to get the decimals in the output as well. Could you please be more specific.

    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

Upvotes: 0

Dmitrij Holkin
Dmitrij Holkin

Reputation: 2055

Please Use Comma , instead of dot .

Upvotes: 1

Related Questions