'Cancel' on User Prompt Box

K

kmzito

Good evening,

When the 'Please Enter Vendor Name" prompt appears it gives you 'Ok'
and 'Cancel'. If you press okay it cycles through the way it should
but when you press cancel, it automatically goes to the first blank
row and asks you if this is correct. I'd like it to be if you press
cancel, that's it, No more!


Dim sUsername As String
Dim sPrompt As String

sPrompt = "Please enter vendor name"
sUsername = InputBox(sPrompt, sTitle, sDefault)

Sheets("list").Select
Range("d4").Select
Cells.Find(What:=sUsername, After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Select

Answer = MsgBox("Is this the contract/vendor you would like to
delete?", vbYesNo + vbInformation, "Please Confirm")
If Answer = vbYes Then
Selection.EntireRow.Delete

Exit Sub
 
B

Bernie Deitrick

sUsername = InputBox(sPrompt, sTitle, sDefault)
If sUsername = "" Then
MsgBox "You cancelled"
Exit Sub
End If

HTH,
Bernie
MS Excel MVP
 
F

FSt1

hi
capture the cancel event.
Sub kmzito()
Dim sUsername As String
Dim sPrompt As String

sPrompt = "Please enter vendor name"
sUsername = InputBox(sPrompt, sTitle, sDefault)

If sUserName = "" Then
MsgBox "nothing was entered." & vbNewLine & "process termiated!"
Exit Sub
Else
' the rest of your code here
End If

End Sub

regards
FSt1
 

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

Top