An implementation of Visual Basic that is built into Microsoft products.
Hi Kermer,
Thank you for raising this question.
Based on the behavior shown in your sample, the issue appears to be related to how VBA manages an active error handler rather than a problem with On Error GoTo 0.
When Sheets(Name).Select raises an error, execution transfers to NEXTA, making that handler active. The code then falls through to NEXTB without executing a Resume, Exit Sub, Exit Function, or Exit Property statement. As a result, the procedure remains within the original error-handling context, which can prevent subsequent On Error GoTo NEXTA statements from behaving as expected.
A minimal change would be to explicitly exit the active handler by using:
NEXTA:
Call Add_A_Name(Name, EnvNo)
Resume NEXTB
As an alternative approach, you could follow the pattern suggested by Bruno Caetano de Brito and check whether the worksheet exists before attempting Sheets(Name).Select. This avoids using error handling as part of the program's execution flow and can help prevent similar issues when the code runs multiple times.
I hope this helps clarify why the behavior occurs and why On Error GoTo 0 alone does not resolve it in this scenario.
If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you.