AutoMacro has been used by employees of these organizations. These organizations do not endorse, approve, sponsor, or otherwise have any affiliation with this website, Spreadsheet Boot Camp LLC, or ToolFive Software LLC.
Online VBA Code Formatter
To quickly indent VBA Code, check out our online VBA Code Formatter
Or continue reading to learn about our free VBA Formatter Add-in.
VBA Auto-Indenter (Free)
Proper code indentation is absolutely essential when coding VBA. Without proper indentation your code will be hard to read and review, increasing the possibility of errors.
Unfortunately VBA does not automatically indent or format your code. However, Our VBA Editor add-in: AutoMacro has an auto-indent tool (free) as well as many other code formatting tools (It also has a suite of other features: VBA Code Generators, Code Libraries, and other utilities. Scroll down to learn more!).
AutoMacro's auto-indenter, automatically indents your code with a click of a button.
64 bit Indentation
AutoMacro's code indenter works in 32-bit Office and 64-bit.
Why Should you Indent Your Code?
Properly formatting and indenting your code saves you time and reduces errors. There are several specific benefits to properly formatting your VBA code:
- You can see at a glance where your code block ends. You don't need to scan each individual line of code to see where your If blocks, Loop Blocks, and With Blocks end.
- You won't get confused when you nest a code block inside another. You can more easily see if your Loop Block is inside your If Block.
- It is much easier to see when a line of code is in the wrong place.
- You can scan your code and narrow your focus into a specific block (Ideally with a comment above it).
- Easier for someone else to review. You may be very familiar with your code, but your colleagues may not be. Properly formatting your code makes it easy for others to read your code.
How to Indent VBA Code?
To indent code, simply press the TAB key. Press the tab key again to add a second code indention.
Generally, you want to add one indentation for each code block. Examples of code blocks are:
- If Statements
- Withs
- Loops & Fors
You probably also want to indent all code within a procedure. This allows you to see where a procedure starts and ends.
Other VBA Code Formatting Tools
The VBA Editor lacks many code formatting tools commonly found in other code editors. AutoMacro's premium code formatting tools were created to fill this gap, allowing you to easily beautify your code.
Clean Excess Line-breaks
Quickly remove excess line breaks within an entire code module with a click of a button.
Sort VBA Code
AutoMacro's smart sort feature allows you to sort your code module without copying and pasting. Just open the sort dialogue box and move your code procedures to their desired locations.
Comment / Uncomment Multiple Lines of Code at Once
AutoMacro allows you to comment / uncomment multiple lines of code at once. It's smart enough to recognize when some lines are commented and others are not, smartly commenting or uncommenting the entire block.
Show VBA Line Numbers
Unfortunately, unlike other code editors, the VBA Editor doesn't show VBA line numbers, but AutoMacro has this functionality.
Other AutoMacro Features
Code Library
200+ Ready-to-use code examples.
Save your own frequently used code and share with team members.
Code Generators
Code Generators build code from scratch via visual interfaces.
No coding knowledge required!
Many More Code Tools
Formatting Tools
Navigation Tools
Misc. Utilities
Excel / VBA Debugger
Join the Hundreds of Professionals Who Use AutoMacro
"Great product, haven’t stopped using it since I purchased it. It doesn’t just write your code, it teaches as you go!"
Tony D - United Kingdom
Steve Rynearson:
Creator of AutoMacro
Over the years, I've spent countless hours searching online for example code and adapting that code to my needs.
I often found myself clicking the same links and copying the same code. I thought there has to be a better way!
AutoMacro eliminates much of this need to search online for code. Instead simply use the menus to select pre-built code or use the builders to generate code for your exact needs.
Additionally, the coding tools will save you time and help you develop more professional looking code.
For anyone coding VBA, AutoMacro is a life-saver. You'll code much faster, develop more professional code, and learn VBA much faster (if you're not already an expert).