ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   POSITION OF ErrorHandler? (https://www.excelbanter.com/excel-programming/402236-position-errorhandler.html)

FARAZ QURESHI

POSITION OF ErrorHandler?
 
My code as below works great. The only problem is that the ErrorHandler
message shows up even if the complete task works perfect!

Is it only that I have placed the ErrorHandler somewhere incorrectly?

Sub FARAZCUT()

On Error GoTo ErrorHandler
Range("A4").End(xlDown).Select
ActiveCell.Offset(1, 0).Activate

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

Range("H5:H3099").Select
Range("H3099").Activate
Selection.FormulaR1C1 = _
"=IF(ISNUMBER(RC[-1]),DATEDIF(RC[-1],NOW(),""Y""),"""")"

Range("AF5:AF3099").Select
Range("AF3099").Activate
Selection.FormulaR1C1 = _
"=+SUM(RC[-2],RC[-4],RC[-6],RC[-8],RC[-10],RC[-12],RC[-14])"

Range("AU5:AU3099").Select
Range("AU3099").Activate
Selection.FormulaR1C1 = _
"=+SUM(RC[-2],RC[-4],RC[-6],RC[-8],RC[-10],RC[-12],RC[-14])"
Range("BG5:BG3099").Select
Range("BG3099").Activate
Selection.FormulaR1C1 = "=+RC[-4]+RC[-3]-RC[-2]+RC[-1]"

Range("BL5:BL3099").Select
Range("BL3099").Activate
Selection.FormulaR1C1 = "=+RC[-4]+RC[-3]-RC[-2]+RC[-1]"

Range("BM5:BM3099").Select
Range("BM3099").Activate
Selection.FormulaR1C1 = "=+RC[-6]-RC[-1]"

Range("BW5:BW3099").Select
Range("BW3099").Activate
Selection.FormulaR1C1 = "=IF(AND(RC[-11]=0,RC[-16]=0),0,1)"

Range("BY5:BY3099").Select
Range("BY1722").Activate
Application.CutCopyMode = False
Selection.FormulaR1C1 = _
"=IF(AND(RC49=""ADJUSTED"",RC59=0,RC64=0),0,COUNTA (RC1:RC76)-7)"

Range("A4").End(xlDown).Select
ActiveCell.Offset(0, 77).Activate
Range(Selection, Selection.End(xlUp)).Select
ErrorHandler:
MsgBox "Copy Something First!"
End Sub



Bill Renaud

POSITION OF ErrorHandler?
 
You need the following line right before ErrorHandler:

Exit Sub

(You have to jump around any error handler. Re-read the topic "On Error
Statement" in Visual Basic Help.)

--
Regards,
Bill Renaud




FARAZ QURESHI

POSITION OF ErrorHandler?
 
THANX BILL!!!

"Bill Renaud" wrote:

You need the following line right before ErrorHandler:

Exit Sub

(You have to jump around any error handler. Re-read the topic "On Error
Statement" in Visual Basic Help.)

--
Regards,
Bill Renaud






All times are GMT +1. The time now is 03:38 AM.

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