Clicking Cancel on an Inputbox

  • Thread starter Thread starter rott
  • Start date Start date
R

rott

Hi I currently have a macro that brings up an input box. The inputbo
allows the user to enter in a date and if they click ok it proceed
with the rest of the macro.

If the user hits cancel or the x in the corner of the inputbox i
continues to loop until they enter a correct date in. What I am tryin
to do is have the macro end if they hit the cancel button.

Can someone help me out?

Thanks!
 
Excel does not capture details of which button is pressed


Ans = InputBox("Prompt", "title")
If Ans = "" Then
End
End If

You will get the same response if the user presses the ok butto
without entering anything as the user pressing the cancel button
 
Use Application.Inputbox - it returns the value False if canceled.

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
From a previous post of mine

Const Msg1 As String = "Enter today's date"
Const Msg2 As String = "You did not enter a valid date." & _
vbNewLine & "Please enter today's date"
Dim UInput As Variant
Dim bLoop As Boolean

Do
UInput = Application.InputBox( _
Prompt:=IIf(bLoop, Msg2, Msg1), _
Default:=Date)
If UInput = False Then Exit Sub
bLoop = True
Loop Until IsDate(UInput)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Input Box Cancel function 4
Cancel Input Box error 16
How to activate InputBox Cancel Function 4
Cancel InputBox 6
Userform cancel problem 4
InputBox Cancel Button 1
question about the Marco inputbox. 0
InputBox 3

Back
Top