Excel VBA - Using Error Traps where Another Routine is Called

0 votes

I have a module with a number of procedures, each of which is called by a separate statement. I'm attempting to include error traps in each procedure, however the traps are activated even when there isn't an error.

Example

public sub Macro1()

*some DIM statements*

On Error GoTo Errhandler

*some code
*
errhandler: MsgBox "Error! Contact developer"
Exit Sub


Call AnotherRoutine

End Sub

In case this had to do with the order of the coding, I tried putting the errhandler statement below the Call statement, but I still had the same issue.

Jan 12, 2023 in Others by Kithuzzz
• 38,000 points
369 views

1 answer to this question.

0 votes

Macro1 is illegible as syntax. After the error handler, I believe you meant to say End Sub. Not like managing circumstances with an If, error handling is different. Simply put, the label is a spot in the code to go to in the event of an error.

To check for errors, you can either enclose the message box with an If or add an Exit Sub immediately above the label.

Public Sub Macro1()
    On Error Goto ErrHandler
    ...
    If Err > 0 Then MsgBox MYMESSAGE
End Sub
answered Jan 12, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

Excel - How can I get the average of cells where the value in one column is X and the value in another column is Y?

Use AVERAGEIFS ... =AVERAGEIFS(C2:C13,A2:A13,"Yellow Typ ...READ MORE

answered Nov 11, 2022 in Others by narikkadan
• 63,600 points
1,398 views
0 votes
1 answer

Activating a Specific Cell in Excel Using VBA Results to Error 400

I think you trying to select cells(4, ...READ MORE

answered Dec 27, 2022 in Others by narikkadan
• 63,600 points
545 views
0 votes
1 answer

Excel file download using java - Error : File is corrupted

Try this: @GetMapping("/downloadDOA") public ...READ MORE

answered Dec 28, 2022 in Others by narikkadan
• 63,600 points
2,325 views
0 votes
0 answers

Convert Rows to Columns with values in Excel using custom format

1 I having a Excel sheet with 1 ...READ MORE

Feb 17, 2022 in Others by Edureka
• 13,690 points
975 views
0 votes
1 answer

Remove formulas from all worksheets in Excel using VBA

Try this : Option Explicit Sub test1() ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
2,019 views
0 votes
1 answer

Calculate monthly average from daily data without PivotTable

Assuming you have the months in column D enter ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,600 points
1,762 views
0 votes
1 answer

Automate compound annual growth rate (CAGR) calculation

The following PowerPivot DAX formulas worked for ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 63,600 points
1,280 views
0 votes
1 answer

Runtime error 438 while importing data in excel from secured website using VBA

Replace With ieDoc.forms(0) .userType.Value = "1" ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
889 views
0 votes
1 answer

Excel offset where reference is to another worksheet

Solution:  =OFFSET((INDIRECT(ADDRESS(1,1,,,"Sheet2")),ROW(),0,,) References: OFFSET(starting point, num of rows, num ...READ MORE

answered Oct 8, 2022 in Others by narikkadan
• 63,600 points
2,292 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP