View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
external usenet poster
 
Posts: 538
Default Exit when Cancel clicked.

Claus Busch wrote:

Am Mon, 6 Jun 2016 08:58:01 -0700 (PDT) schrieb :

At present, if "Cancel" is clicked a blank row is added. I would like
the routine to simply exit without doing anything if Cancel is clicked.
I've googled these and have seen various ways of doing it but NOT in
tandem with inputting to a cell.


I can't reproduce this behaviour. I guess the user enters a space and
press OK.
You can check the InputBox for space:

emptyRow = ActiveSheet.Cells(Rows.Count, "C").End(xlUp)(2).Row

'Transfer information from form to Event Budget Inputs sheet
val1 = InputBox("Enter the new Category", "BizApp New Category")
If val1 = "" Or val1 = Chr(32) Then Exit Sub


Or just:

If Trim(val1) = "" Then Exit Sub

val2 = InputBox("Enter the budgeted amount for the new Category",
"BizApp New Category")
If val2 = "" Or val1 = Chr(32) Then Exit Sub

^^^^ typo; should be val2

If Trim(val2) = "" Then Exit Sub

Cells(emptyRow, 3).Value = val1
Cells(emptyRow, 4).Value = val2

MsgBox "New Category added."


--
- What are you afraid of?
- Dying without purpose.