Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value of Cancel button

Status
Not open for further replies.

snoopy80

Technical User
Jun 27, 2001
106
Good Morning!
I have an inputbox I use to request date from users in an Excel sheet. And according what the user enter, it will perform certain fuctions and if the user click on Cancel I want to have an If statement to detect this event and perform other fuctions. I have:

Opt=inputbox("....")

What Opt is equal to when user press the Cancel key?

Thanks for help
 
Application.InputBox returns False if Cancel is clicked.
VBA.InputBox returns "" if Cancel is clicked.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Open the VB eidtor in Exel. Press the F1 key. Type the word 'InputBox' then press enter. Click on the first search result. Read and you will find this sentence:

If you click the Cancel button, InputBox returns False.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Depends on which InputBox you use. If it's the VBA function, it reurns an empty string if the user presses Cancel. Unfortunately, your program can't distinguish that result from one where the user clicks OK without entering anything. I like to use the InputBox Method of the Application object, which returns False if Cancel is selected. See the Help file for syntax.


HTH
Mike
 
Thank you All for Help.
I modified my Inputbox to Application.Inputbox and the Cancel click return False. My codes are working great.

Thanks Again!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top