ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error handling does not work (https://www.excelbanter.com/excel-programming/389295-error-handling-does-not-work.html)

keri

Error handling does not work
 
On running this code;

On Error GoTo SKIPERROR

Range("M14:M20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("n14:n20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("O14:O20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("P14:P20").SpecialCells(xlCellTypeBlanks).De lete xlUp

skiperror:
Range("a18") = Range("n14")
Range("b18") = Range("n15")
Range("c18") = Range("n16")
Range("d18") = Range("n17")
Range("e18") = Range("n18")
Range("f18") = Range("n19")
Range("g18") = Range("n20")
Range("h18") = Range("n21")
Range("i18") = Range("n22")
Range("j18") = Range("n23")

I get a run time error 1004 - No cells were found
I thought the skiperror would handle this but it doesn't - please tell
me where I am going wrong!


merjet

Error handling does not work
 
If you want to skip error handling use:
On Error Resume Next

Hth,
Merjet



Jim Rech

Error handling does not work
 
Every error handler must have a Resume statement unless you are immediately
exiting the sub. The general format is:

Sub MyMacro()


On Error GoTo ErrorHandler
For Counter = 1 to 10
'Do something
StartAgain:
Next
Exit Sub


ErrorHandler:
'Fix problem, etc.
Resume StartAgain
End Sub


While you are "in the error handler" you have no error handling. After the
Resume error handling will be back, you do not need an other On Error:


Sub MyBadMacro()
On Error GoTo ErrorHandler
For Counter = 1 To 10
x = 1 / 0
StartAgain:
Next
Exit Sub


ErrorHandler:
Debug.Print Counter
Resume StartAgain
End Sub


If you want to just ignore the error you can use On Error Resume Next. Use
this judiciously as it can hide problems from you that you should be aware
of.

--
Jim

"keri" wrote in message
ups.com...
On running this code;

On Error GoTo SKIPERROR

Range("M14:M20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("n14:n20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("O14:O20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("P14:P20").SpecialCells(xlCellTypeBlanks).De lete xlUp

skiperror:
Range("a18") = Range("n14")
Range("b18") = Range("n15")
Range("c18") = Range("n16")
Range("d18") = Range("n17")
Range("e18") = Range("n18")
Range("f18") = Range("n19")
Range("g18") = Range("n20")
Range("h18") = Range("n21")
Range("i18") = Range("n22")
Range("j18") = Range("n23")

I get a run time error 1004 - No cells were found
I thought the skiperror would handle this but it doesn't - please tell
me where I am going wrong!




Dana DeLouis

Error handling does not work
 
On Error GoTo SKIPERROR
skiperror:


Hi. Your code should work, but did you copy the code from the module as is?
The reason I ask is that the case of the two words "SkipError" are
different.
GoTo SKIPERROR should match the case "skiperror"
ie GoTo skiperror
If copied, this tells me you may have a problem elsewhere.

As an alternative...

Sub Demo()
On Error Resume Next
Range("M14:P20").SpecialCells(xlCellTypeBlanks).De lete xlUp
On Error GoTo 0
[A18:J18] = [Transpose(N14:N23)]
End Sub

--
HTH :)
Dana DeLouis
Windows XP & reluctantly using Excel 2007


"keri" wrote in message
ups.com...
On running this code;

On Error GoTo SKIPERROR

Range("M14:M20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("n14:n20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("O14:O20").SpecialCells(xlCellTypeBlanks).De lete xlUp
Range("P14:P20").SpecialCells(xlCellTypeBlanks).De lete xlUp

skiperror:
Range("a18") = Range("n14")
Range("b18") = Range("n15")
Range("c18") = Range("n16")
Range("d18") = Range("n17")
Range("e18") = Range("n18")
Range("f18") = Range("n19")
Range("g18") = Range("n20")
Range("h18") = Range("n21")
Range("i18") = Range("n22")
Range("j18") = Range("n23")

I get a run time error 1004 - No cells were found
I thought the skiperror would handle this but it doesn't - please tell
me where I am going wrong!





All times are GMT +1. The time now is 02:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com