Andreas Hermle
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If users are using a comma for the decimal separator then you'll need to replace it with '.' before you do the comparison.
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
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
ASKER
Thank you to all of you, great forum, great experts!
You're welcome Andreas! Glad it worked as desired.
you should reformat your codes for the ease of reading and troubleshooting
Open in new window