Is there anyway to fix it on VBA so that when you press cancel on pop up boxes it doesn't come up with a debug error but actually cancels?
More information needed.
In excel using VBA a inputbox asks for something, you normally type this in and press OK.There is also a cancel button which should stop running the code however pressing the cancel causes a type mismatch all the type and brings up a excel error.
If you were to use the following statement iNumber = InputBox(prompt:="Please enter a number")you will get a type mismatch error message since variable iNumber has been declared to be an integer and the input box always returns text.Using Val in front of the InputBox will convert the response into a number and avoids the error message:iNumber = Val(InputBox(prompt:="Please enter a number"))However, if the user selects cancel, the resulting "" would be converted to a 0. And there would be no way to determine if the user selected cancel or entered a 0.If zero is not a valid response and you do not wish to confirm that the user pressed the cancel button, then you can use the following instead:iNumber = Val(InputBox(prompt:="Please enter a number"))If iNumber = 0 Then End
Sub Get_A_Number()Dim response As Variant, numberEntered As Integerresponse = Application.InputBox (prompt:="Please enter a number", Type:=1)If Str(response) = "False" Then Exit SubnumberEntered = responseMsgBox "You entered " & numberEnteredEnd Sub
How would you do it for a string inputbox.If response="false" doesn't seem to pick up on pressing a cancel button there.
If Str(response) = "False"should work.
This thread is now locked and can not be replied to.
iMac Pro review
Illustrator Charles Williams on how to create magazines and book covers
Les meilleures prises CPL (2018)
© Copyright 2018 IDG UK. All Rights Reserved.