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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End Sub if Cancel selected 1

Status
Not open for further replies.

makeitwork09

Technical User
Sep 28, 2009
170
US
I am using Excel 2007

I was wording how I could improve the following code so that if the user
selects Cancel the routine will stop and no subsequent code will execute?

Code:
Sub checkInt()
   Dim ValidPSA

   ValidPSA = Application.InputBox(prompt:="Enter the most recent PSA",
Type:=1)

    On Error Resume Next
    If IsNumeric(ValidPSA) Then
          'int function rounds number, if it equals the cell, then number
is an interger
          If ValidPSA > 0 And ValidPSA - Int(ValidPSA) = 0 Then
              Call CashflowQuery(ValidPSA)
          Else
              MsgBox "Not a Positive Integer: " & ValidPSA
          End If
    Else
       MsgBox "The entry was invalid"
    End If

End Sub

Thanks
 
...
ValidPSA = Application.InputBox(prompt:="Enter the most recent PSA", Type:=1)
If ValidPSA = False Then
Exit Sub
End If
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, but wouldn't that allow users to enter numbers that are not positive integers?

The current code is set up so that only positive integers are accepted.

Thanks

M09
 



...but wouldn't that allow users to enter numbers that are not positive integers?
HUH?

What does THAT have to do with the posted question???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip, the question was in reference to the posted code.

I was wording how I could improve the following code so that if the user
selects Cancel the routine will stop and no subsequent code will execute?

The code is checking that the entry is valid, but it is not good in that it does not handle if the user clicked cancel.

Thanks
 
I thought the code PHV posted, though it would (1) take a number and (2) properly handle the Cancel choice, it does not stop a user from entering a non positive integer.

But, now as I write this, I suspect I can test that after the code that PHV posted.
 


No one can read your mind. PHV answered the question that you asked!

What's the big deal?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Combining what PHV provided with the code I provided I was able to do what I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top