Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Maximum Length Limit for a Macro.

Maximum Length Limit for a Macro

by Allen Wyatt
(last updated July 22, 2020)


Vasant has written a very long macro in Excel—over 1,400 lines. When he tries to run the macro, Excel refuses to run it and says that it is too long.

Excel apparently has a limit on VBA code such that you cannot have more than 64K of compiled code in a single procedure. The solution to this problem is to chop up your long macro into shorter procedures. For instance, you might divide your monster macro into, say, a dozen smaller macros. You can make the smaller macros Private instead of Public (so they don't show up in the Macros list in Excel), and then call them sequentially from a "controller" macro.

When you separate your code into individual procedures, make sure that each separate procedure has all loops and logic self-contained. Also make sure that any variables used in more than one procedure are declared as global variables so they are accessible by all the procedures.


If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10449) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Maximum Length Limit for a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Jumping to the Ends of Table Rows

Need to jump from one end of a table row to another? Word provides a couple of handy shortcuts that can make this type of ...

Discover More

Select All Changes By a Particular Reviewer

The Track Changes feature in Word allows you and other editors to easily collaborate on the development of a document. If ...

Discover More

Easily Changing Chart Data Ranges

Want a handy way to make the data ranges for your chart more dynamic? Here are some great ideas you can put to work right ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Automating Copying Macros

You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...

Discover More

Determining the Current Directory

When you use a macro to do file operations, it works (by default) within the current directory. If you want to know which ...

Discover More

Determining the Day of the Month

Want to figure out the day of the month represented by a particular date? You can use the Day function in VBA to get the ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 + 8?

2020-05-17 11:23:09


A Macro of 1400 lines? I hope the majority are comments. Nevertheless this is more a chapter of a novel instead of program code. A guideline that I found always useful is when your code becomes bigger than one page, and you louse the overview to understand it, split it.

2014-09-02 11:03:13


balthamossa...I think it means it loads and executes on a subroutine by subroutine basis. Since I keep functions grouped by purpose, e.g. those that return Worksheets, in modules separate from the Subs related to a specific task, it could not be working on a Module-level.

Tony....fully agree. I started my IT life trying to decipher un-modularized code. It's a nightmare.

Ken...carrying on with Tony's point, a 64k limit may not be necessary from a technical standpoint but it does discourage run-on subprocedures and their inherent problems. Way back when, the guideline was that each unit of code should have one purpose. This wasn't because of memory limits. It makes the code more testable, maintainable and re-usable by call instead of copy & paste.

In the case of a SUB or FUNCTION that is "too long" (by whatever measure one wishes to use, if there are a x lines in the Sub to make a decision, why not move that section to a Function, making it a testable, maintainable, and possibly re-usable-by-call unit of code?

I guess my point is that simply because a limitation can be removed is it always best to remove it? What is the value of a single Sub that is 128K long versus the same code split into Functions and Subs that might total 160K (adding a generous factor for new procedural headers, ENDs, and call statements). Disk an memory are cheap, labor to troubleshoot and repair are not.

Just my opinions...I guess it was pent up from a 3 day weekend.

2014-09-01 04:21:44


So does this mean Office stores all subs individually, not by modules?


2014-09-01 03:09:51


As a programmer by trade, I wouldn't have a macro of 1,400 lines; I prefer to break my code down for two reasons.
(1) move duplicate code into another macro (just like a subroutine) so that it's easier to maintain.
(2) If code is still large, break chunks of logic into another macro so that the main code is easier to read (and maintain). For example, if you're importing data into excel from a csv file with different record types, you could have a macro per record type.

2014-08-30 18:43:06


I have run up against the size limit but I didn't know exactly what it is, nor do I know know to find out the compiled size of a macro anyway. It is, however, completely absurd and should deeply embarrass Microsoft - 64k limits were obsolete when the world moved from DOS to Windows and have no place in one of the company's flagship products. Is ther any likelihood of them fixing this problem?

2014-08-30 11:46:39

Scott L

That's interesting. I knew there was a limit, but not what it was and I do break up my routines into subroutines. What about this scenario? I created an addin that contains all the frequently used macros I’ve collected over the years. It modifies the ribbon, adding new groups to every tab and a new tab that has buttons for all the macros, including a half dozen dynamic menus. I’ve found that some macros that run in other workbooks won’t run when the addin is loaded. If I unload it, they run fine, but not if it’s loaded. I must be running up against some other limit and I’m wondering what that is and how to deal with it.

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.