+ Reply to Thread
Results 1 to 4 of 4

To Call or not to Call

  1. #1
    Registered User
    Join Date
    05-28-2014
    Location
    Planet Earth
    MS-Off Ver
    Office 365 - Excel
    Posts
    1

    Question To Call or not to Call

    What is the best practice ..... to write longish macros or to write shorter macros and use Call statements. I recently completed a project that imported data (from Quicken) into Excel, prepped that data and then added it to a Excel Table/Database. I broke each of the different prep types into separate Macros and then used Call to link the prepping Macros to a "master" Macro. Is this better or worse in terms of execution and speed than combining all the lines together in one long(ish) Macro for all the prep work? The smaller Subs are 20 to 50 lines each (not including comments) and could be consolidated into a single sub of say 350 to 400 lines.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: To Call or not to Call

    Break the big one up; but, use descriptive names for the called subs to make the logic apparent.
    Ben Van Johnson

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: To Call or not to Call

    If you have a VBA application where you are starting to worry about optimizing the stack, then you into some heavy stuff. There are many ways to optimize VBA for Excel and Sub calls is rarely a major culprit in performance problems. More common is the failure to take advantage of structures specific to Excel, such as doing massive calculations using cell references, instead of loading data into arrays for processing. And even then you have to have a big, long-running application before you see improvements from the user's perspective.

    The rule of thumb is that you should first structure your code in a way that is logical, and minimizes the impact of recoding if you have to make a change later. No point in saving 10 seconds of run time by spending extra hours to code something, and even more hours when you have to go back in 6 months to modify the code and ask, "Now, what was I thinking when I coded this?"

    If it ain't broke, don't fix it. Are you experiencing a performance problem? If not, don't consolidate the code. If you are, look at other issues first. Post your file here and we can help out.

    (Note that I moved this to the VBA subforum.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: To Call or not to Call

    My suggestion = Write a main macro which calls sub macros.

    1. Placing all the code into one long macro in order to reduce Call statements will not save you noticeable speed because the speed impact of using Call is negligible (see http://www.excelforum.com/excel-prog...e-fastest.html ).

    2. If you keep the sub macros generic you are creating reusable code (which can save you time in future projects)

    3. If there are a lot of variables in your code, IMO it would be best to avoid long macros because of the increased overhead. By moving as many as possible to sub macros, they are only used when needed and lose scope as soon as the sub macro ends.

    4. I second what 6StringJazzer says. If your code is running that slow then there are more important things to optimize to improve your speed.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Repeat call count for call center
    By arifmasum in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-08-2013, 10:03 PM
  2. How to set call count according to call date and time
    By naveen4pundir in forum Access Tables & Databases
    Replies: 0
    Last Post: 04-27-2012, 02:13 AM
  3. VBA Call
    By TYork in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2010, 03:27 PM
  4. using CALL to call methods mandatory?
    By jerryliang2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2008, 06:16 PM
  5. Replies: 2
    Last Post: 06-25-2006, 12:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1