Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default End Sub if InputBox cancelled (False)

Input Box Cancel button should stop the subroutine.



OK button tests to see if 'x' has been changed.



I cannot see what is wrong he



LastUsedRow = Sheets("Pages").Cells(Rows.Count, 5).End(xlUp).Row

DoorNum = Cells(LastUsedRow, 5)

x = InputBox("Door number?", _

"Additional items to door", DoorNum, 1)

If x = False Then

End

ElseIf x < DoorNum Then

DoorNum = x

End If



Francis Hookham


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default End Sub if InputBox cancelled (False)

Input Boxes return strings, not T/F. A Cancelled Input box returns an empty
string: ""

Select Case x
Case ""
' User Canceled
Exit Sub
Case DoorNum
' x hasn't changed: do nothing
Case Else
' x has changed
DoorNum = x
End select


"Francis Hookham" wrote in message
...
Input Box Cancel button should stop the subroutine.



OK button tests to see if 'x' has been changed.



I cannot see what is wrong he



LastUsedRow = Sheets("Pages").Cells(Rows.Count, 5).End(xlUp).Row

DoorNum = Cells(LastUsedRow, 5)

x = InputBox("Door number?", _

"Additional items to door", DoorNum, 1)

If x = False Then

End

ElseIf x < DoorNum Then

DoorNum = x

End If



Francis Hookham




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default End Sub if InputBox cancelled (False)

I think that when you cancel an input box, a zero length string is returned.
As such, replace this:

If x = False Then

with this:

If x = "" Then

-Cory


"Francis Hookham" wrote:

Input Box Cancel button should stop the subroutine.



OK button tests to see if 'x' has been changed.



I cannot see what is wrong he



LastUsedRow = Sheets("Pages").Cells(Rows.Count, 5).End(xlUp).Row

DoorNum = Cells(LastUsedRow, 5)

x = InputBox("Door number?", _

"Additional items to door", DoorNum, 1)

If x = False Then

End

ElseIf x < DoorNum Then

DoorNum = x

End If



Francis Hookham



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default End Sub if InputBox cancelled (False)

If you use Application.InputBox the Cancel will = False
but with InputBox Function, Cancel = ""

"Cory" wrote:

I think that when you cancel an input box, a zero length string is returned.
As such, replace this:

If x = False Then

with this:

If x = "" Then

-Cory


"Francis Hookham" wrote:

Input Box Cancel button should stop the subroutine.



OK button tests to see if 'x' has been changed.



I cannot see what is wrong he



LastUsedRow = Sheets("Pages").Cells(Rows.Count, 5).End(xlUp).Row

DoorNum = Cells(LastUsedRow, 5)

x = InputBox("Door number?", _

"Additional items to door", DoorNum, 1)

If x = False Then

End

ElseIf x < DoorNum Then

DoorNum = x

End If



Francis Hookham



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default End Sub if InputBox cancelled (False)

Many thanks George and Cory - all's well now

I was trying to use False because I read in VBA Help - InputBox Remarks:

If you choose the OK button, InputBox returns the value entered in the
dialog box. If you click the Cancel button, InputBox returns False.

Francis Hookham


"George Nicholson" wrote in message
...
Input Boxes return strings, not T/F. A Cancelled Input box returns an
empty string: ""

Select Case x
Case ""
' User Canceled
Exit Sub
Case DoorNum
' x hasn't changed: do nothing
Case Else
' x has changed
DoorNum = x
End select


"Francis Hookham" wrote in message
...
Input Box Cancel button should stop the subroutine.



OK button tests to see if 'x' has been changed.



I cannot see what is wrong he



LastUsedRow = Sheets("Pages").Cells(Rows.Count, 5).End(xlUp).Row

DoorNum = Cells(LastUsedRow, 5)

x = InputBox("Door number?", _

"Additional items to door", DoorNum, 1)

If x = False Then

End

ElseIf x < DoorNum Then

DoorNum = x

End If



Francis Hookham








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default End Sub if InputBox cancelled (False)

The Entry in Excel's Help for the Application.InputBox method says that, but
the entry for the VBA InputBox function (in both Access and Excel) says:

"If the user clicks Cancel, the function returns a zero-length string ("")."

At least, that's what I am seeing (using Office 2003)

Not specifying Application means the VBA function will be used, not the
Excel method.

Be careful which Help entries you are reading. Very similar objects,
properties etc. can really be different under the surface across apps.
*Usually* those differences are confined to how a few functions calculate or
Forms (Access Forms live in their own little universe when compared to VB
forms or Office Forms), but there are a few other "gotchas". This is
evidently one of them.

HTH,



"Francis Hookham" wrote in message
...
Many thanks George and Cory - all's well now

I was trying to use False because I read in VBA Help - InputBox Remarks:

If you choose the OK button, InputBox returns the value entered in the
dialog box. If you click the Cancel button, InputBox returns False.

Francis Hookham


"George Nicholson" wrote in message
...
Input Boxes return strings, not T/F. A Cancelled Input box returns an
empty string: ""

Select Case x
Case ""
' User Canceled
Exit Sub
Case DoorNum
' x hasn't changed: do nothing
Case Else
' x has changed
DoorNum = x
End select


"Francis Hookham" wrote in message
...
Input Box Cancel button should stop the subroutine.



OK button tests to see if 'x' has been changed.



I cannot see what is wrong he



LastUsedRow = Sheets("Pages").Cells(Rows.Count, 5).End(xlUp).Row

DoorNum = Cells(LastUsedRow, 5)

x = InputBox("Door number?", _

"Additional items to door", DoorNum, 1)

If x = False Then

End

ElseIf x < DoorNum Then

DoorNum = x

End If



Francis Hookham








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink operation cancelled.... Kim Excel Discussion (Misc queries) 1 June 15th 07 03:24 PM
Avoid unloading of .xla addins when closing books are cancelled. Zoo Excel Programming 4 February 21st 06 03:58 PM
Email Sent or Cancelled mjamici Excel Programming 1 June 15th 05 06:46 PM
Application.InputBox with Default:=0 testing False bluhme Excel Programming 2 June 24th 04 12:35 PM
Differentiate b/w False and 0 with InputBox fn Marcotte A[_2_] Excel Programming 3 June 8th 04 05:10 PM


All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"