Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Meaning of On Error Goto 0

Would one of you please explain the following code to me step by step?

Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
If Err.Number < 0 Then
MsgBox ("You Cancelled The Operation.")
Exit Sub
On Error GoTo 0
End If
MsgBox (x.Address)
End Sub

All I want to do is create an inputbox which ONLY upon hitting the Cancel
Button would display the msgbox "You Cancelled The Operation." and not on any
other error.

All your help and expert advice shall be obliged.

Thanx in advance.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Meaning of On Error Goto 0

To notify cancel please try the below

Dim varInput As Variant
varInput = Application.InputBox("Please enter the value")
If varInput = False Then MsgBox "You cancelled the operation"

On error handling please refer the below link
http://msdn.microsoft.com/en-us/libr...as(VS.80).aspx



If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Would one of you please explain the following code to me step by step?

Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
If Err.Number < 0 Then
MsgBox ("You Cancelled The Operation.")
Exit Sub
On Error GoTo 0
End If
MsgBox (x.Address)
End Sub

All I want to do is create an inputbox which ONLY upon hitting the Cancel
Button would display the msgbox "You Cancelled The Operation." and not on any
other error.

All your help and expert advice shall be obliged.

Thanx in advance.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Meaning of On Error Goto 0

Thanx Jacob,

However, such a code is not correctly working for the Type:=8 inputbox.
Modifying the code to:

Sub test2()
Dim varInput As Variant
varInput = Application.InputBox("Please enter the value", Type:=8)
If varInput = False Then
MsgBox "You cancelled the operation"
Else
MsgBox (varInput.Address)
End If
End Sub

is showing MsgBox "You cancelled the operation" even though I selected a
range, instead of showing the address of the cells.

"Jacob Skaria" wrote:

To notify cancel please try the below

Dim varInput As Variant
varInput = Application.InputBox("Please enter the value")
If varInput = False Then MsgBox "You cancelled the operation"

On error handling please refer the below link
http://msdn.microsoft.com/en-us/libr...as(VS.80).aspx



If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Would one of you please explain the following code to me step by step?

Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
If Err.Number < 0 Then
MsgBox ("You Cancelled The Operation.")
Exit Sub
On Error GoTo 0
End If
MsgBox (x.Address)
End Sub

All I want to do is create an inputbox which ONLY upon hitting the Cancel
Button would display the msgbox "You Cancelled The Operation." and not on any
other error.

All your help and expert advice shall be obliged.

Thanx in advance.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Meaning of On Error Goto 0

Try this..

Sub Macro1()

Dim myRange As Range

On Error Resume Next
Application.DisplayAlerts = False
Set myRange = Application.InputBox(Prompt:= _
"Please select a range", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True

If myRange Is Nothing Then
MsgBox "You cancelled the operation"
Exit Sub
Else
MsgBox myRange.Address
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Thanx Jacob,

However, such a code is not correctly working for the Type:=8 inputbox.
Modifying the code to:

Sub test2()
Dim varInput As Variant
varInput = Application.InputBox("Please enter the value", Type:=8)
If varInput = False Then
MsgBox "You cancelled the operation"
Else
MsgBox (varInput.Address)
End If
End Sub

is showing MsgBox "You cancelled the operation" even though I selected a
range, instead of showing the address of the cells.

"Jacob Skaria" wrote:

To notify cancel please try the below

Dim varInput As Variant
varInput = Application.InputBox("Please enter the value")
If varInput = False Then MsgBox "You cancelled the operation"

On error handling please refer the below link
http://msdn.microsoft.com/en-us/libr...as(VS.80).aspx



If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Would one of you please explain the following code to me step by step?

Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
If Err.Number < 0 Then
MsgBox ("You Cancelled The Operation.")
Exit Sub
On Error GoTo 0
End If
MsgBox (x.Address)
End Sub

All I want to do is create an inputbox which ONLY upon hitting the Cancel
Button would display the msgbox "You Cancelled The Operation." and not on any
other error.

All your help and expert advice shall be obliged.

Thanx in advance.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Meaning of On Error Goto 0

Great!

Excellent introduction of Application.DisplayAlerts = False especially in
case of pressing OK without inserting a range in the InputBox.

Thanx again pal!

"Jacob Skaria" wrote:

Try this..

Sub Macro1()

Dim myRange As Range

On Error Resume Next
Application.DisplayAlerts = False
Set myRange = Application.InputBox(Prompt:= _
"Please select a range", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True

If myRange Is Nothing Then
MsgBox "You cancelled the operation"
Exit Sub
Else
MsgBox myRange.Address
End If

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Thanx Jacob,

However, such a code is not correctly working for the Type:=8 inputbox.
Modifying the code to:

Sub test2()
Dim varInput As Variant
varInput = Application.InputBox("Please enter the value", Type:=8)
If varInput = False Then
MsgBox "You cancelled the operation"
Else
MsgBox (varInput.Address)
End If
End Sub

is showing MsgBox "You cancelled the operation" even though I selected a
range, instead of showing the address of the cells.

"Jacob Skaria" wrote:

To notify cancel please try the below

Dim varInput As Variant
varInput = Application.InputBox("Please enter the value")
If varInput = False Then MsgBox "You cancelled the operation"

On error handling please refer the below link
http://msdn.microsoft.com/en-us/libr...as(VS.80).aspx



If this post helps click Yes
---------------
Jacob Skaria


"FARAZ QURESHI" wrote:

Would one of you please explain the following code to me step by step?

Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
If Err.Number < 0 Then
MsgBox ("You Cancelled The Operation.")
Exit Sub
On Error GoTo 0
End If
MsgBox (x.Address)
End Sub

All I want to do is create an inputbox which ONLY upon hitting the Cancel
Button would display the msgbox "You Cancelled The Operation." and not on any
other error.

All your help and expert advice shall be obliged.

Thanx in advance.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Meaning of On Error Goto 0

The "on error resume next" says that your could expects that an error could come
from the next few(?) lines--until you turn error checking back on.

I'd use:

Option Explicit
Sub test()
Dim x As Range

set x = nothing
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
on error goto 0

if x is nothing then
msgbox "You Cancelled The Operation."
else
MsgBox x.Address
end if

End Sub

FARAZ QURESHI wrote:

Would one of you please explain the following code to me step by step?

Sub test()
Dim x As Range
On Error Resume Next
Set x = Application.InputBox("Select the cells.", Type:=8)
If Err.Number < 0 Then
MsgBox ("You Cancelled The Operation.")
Exit Sub
On Error GoTo 0
End If
MsgBox (x.Address)
End Sub

All I want to do is create an inputbox which ONLY upon hitting the Cancel
Button would display the msgbox "You Cancelled The Operation." and not on any
other error.

All your help and expert advice shall be obliged.

Thanx in advance.


--

Dave Peterson
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
Error dialog box meaning and how to find error Jeanne Excel Worksheet Functions 2 September 4th 08 04:59 AM
Excel 2002: Need to know the meaning of error meesage Mr. Low Excel Discussion (Misc queries) 11 January 25th 08 02:36 AM
On error goto problem Coppercrutch Excel Discussion (Misc queries) 3 December 28th 07 03:04 PM
On Error GoTo Doesn't Work [email protected] Excel Discussion (Misc queries) 2 November 29th 07 09:43 PM
On Error GoTo skip needs help dan Excel Discussion (Misc queries) 2 April 24th 06 06:29 PM


All times are GMT +1. The time now is 02:24 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"