#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Input Box Q

I have a very simple Input Box as below, which asks a user to enter a
value. How can I build in validations within it that will check to
ensure that the value entered is a percentage, between 0% and 99%.
Also can I trap that the user must enter something and is not allowed
just to cancel out of it? My input box below has a OK/Cancel button

Sub test01()
UserValue = InputBox("Value to use?")
Range("B3").Value = UserValue

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default Input Box Q

Hi

Something like

Sub test01()
uservalue = InputBox("Value to use? Between 0% and 99%")
uservalue2 = Format(uservalue, "#.00")
If uservalue2 < 0 Or uservalue2 99 Then
MsgBox "Value outside range of 0% to 99%"
Exit Sub
End If
If uservalue2 1 Then
uservalue = Format(uservalue2 / 100, "#%")
Else
uservalue = Format(uservalue2, "#%")
End If
Range("B3").Value = uservalue
End Sub


--
Regards
Roger Govier

"Seanie" wrote in message
...
I have a very simple Input Box as below, which asks a user to enter a
value. How can I build in validations within it that will check to
ensure that the value entered is a percentage, between 0% and 99%.
Also can I trap that the user must enter something and is not allowed
just to cancel out of it? My input box below has a OK/Cancel button

Sub test01()
UserValue = InputBox("Value to use?")
Range("B3").Value = UserValue

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Input Box Q

Dear Seanie

Try this. You can include more validations ....

Sub test01()

Do
isvalidvalue = True
uservalue = InputBox("Value to use?")
'---Add all validations here and set variable IsValidValue to False if fails
If Trim(uservalue) = "" Then isvalidvalue = False
If CInt(uservalue) < 0 Or CInt(uservalue) 99 Then isvalidvalue = False
'------------
Loop While isvalidvalue = False

Range("B3") = uservalue

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Seanie" wrote:

I have a very simple Input Box as below, which asks a user to enter a
value. How can I build in validations within it that will check to
ensure that the value entered is a percentage, between 0% and 99%.
Also can I trap that the user must enter something and is not allowed
just to cancel out of it? My input box below has a OK/Cancel button

Sub test01()
UserValue = InputBox("Value to use?")
Range("B3").Value = UserValue

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default Input Box Q

Thanks Roger, I've tried to format the output cell as 0.00%, but it
only shows as 0.00, why is that?

uservalue = InputBox("Value to use? Between 0% and 99%")
uservalue2 = Format(uservalue, "#.00")
If uservalue2 < 0 Or uservalue2 99 Then
MsgBox "Value outside range of 0% to 99%"
Exit Sub
End If
If uservalue2 1 Then
uservalue = Format(uservalue2 / 100, "#%")
Else
uservalue = Format(uservalue2, "#.00%")
End If
Range("B3").Value = uservalue
Selection.NumberFormat = "0.00%"

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to input pictures automatically based on cell input? bsharp Excel Worksheet Functions 9 May 30th 09 07:16 AM
Have user input converted to uppercase in same cell as input? Shannonn New Users to Excel 1 June 20th 06 03:19 AM
How do I add input data in the input ranges in drop down boxes. oil_driller Excel Discussion (Misc queries) 1 November 9th 05 10:31 PM
=SUMIF(Input!H2:H718,AZ19,Input!E2:E685)AND(IF ALex Excel Worksheet Functions 2 March 14th 05 09:19 PM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Excel Programming 4 December 8th 03 03:22 PM


All times are GMT +1. The time now is 09:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"