You are here:

Excel/Overhead - Exit Subs



I have an Excel workbook with many time and VBA functions. Is it good policy that if a vba sub does not meet the basic requirements to do an "Exit Sub"?

I am concerned with all the "overhead" that is executing without cause. Is it good practice to reduce as much overhead as possible?

I am still such a novice.



Public Function ABC(r as Range) as Variant
' assign error value to function
ABC = CvErr(xlErrRef)
if r.cells.count > 1 then exit Function

' code to perform the function purpose with single cell reference
'. . .

' assign value to function
ABC = "some value"

End Function

This would produce the #REF error in a cell if the argument was not to a single cell.

So I jump out of the function when it is obvious conditions are not met.

Traditionalists would say that there should only be one exit location for a procedure because having multiple exit points make it hard to maintain.  If you are going to provide it as part of a team and/or others need to maintain your code, then you probably need to be more strict in your coding practice - but your team lead should spell those out.  In my opinion, there is nothing wrong with jumping out early as long as you know what you are doing.  I have even seen some seasoned VBA programmers advocate the use of GoTo when it is appropriate.  In fact, the error handling in VBA is based on a modification of Go

On Error goto ErrHandler


Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 All rights reserved.