Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

inputbox does not allow for entering certain numbers although the range has been correctly specified

Dear Experts:

Below inputbox code (which resizes selected graphics) allows for entering values between 1.5 and 3.8

If I enter a value between 1.5 and 1.9, then I get the message MsgBox "Size must be between 1.5 and 3.8 cm!"
If I enter a value between 2 and 3.8 everything works fine.

What is wrong?


Help is very much appreciated. Thank you very much in advance.

Regards, Andreas


Sub resize_graphic()
Dim graphic_size As String

graphic_size = Application.Inputbox(Prompt:="Enter the new size of the selected graphics!" & vbCrLf & _
"Enter a comma for the decimal place!", _
Title:="Resize graphics", Default:="Enter number between 1.5 and 3.8 cm.")

If Not IsNumeric(graphic_size) Then
MsgBox "You can only enter a number in this field"
Else
Size = Val(graphic_size)
If Size < 1.5 Or Size > 3.8 Then
MsgBox "Size must be between 1.5 and 3.8 cm!"
Else
Selection.ShapeRange.Height = Application.CentimetersToPoints(graphic_size)

End If
End If

End Sub

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

just tested your codes with values 1.5 and 1.9, it is working fine!

you should reformat your codes for the ease of reading and troubleshooting

Sub resize_graphic()
    Dim graphic_size As String
    
    graphic_size = Application.InputBox(Prompt:="Enter the new size of the selected graphics!" & vbCrLf & _
                    "Enter a comma for the decimal place!", _
                    Title:="Resize graphics", Default:="Enter number between 1.5 and 3.8 cm.")
    
    If Not IsNumeric(graphic_size) Then
        MsgBox "You can only enter a number in this field"
    Else
        Size = Val(graphic_size)
        If Size < 1.5 Or Size > 3.8 Then
            MsgBox "Size must be between 1.5 and 3.8 cm!"
        Else
            Selection.ShapeRange.Height = Application.CentimetersToPoints(graphic_size)
        End If
    End If

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

If users are using a comma for the decimal separator then you'll need to replace it with '.' before you do the comparison.
Avatar of Andreas Hermle

ASKER

dear both,

I am pretty sure the code only works on your end because you have the english version of Excel. I got the German version (we use a comma for decimal places).

Anyhow, declaring the variable did the trick. Thank you very much Neeraj
Thank you to all of you, great forum, great experts!
You're welcome Andreas! Glad it worked as desired.