All courses available in-class or via remote login

Reading glasses in front of computer screens

4 Tips for VBA Excellence

October 30, 2017

Tips and tricks


When we encounter a new language not to mention a programming language, it is understandable to be apprehensive about it. If you are trying to automate an Excel spreadsheet using VBA programming, it can seem especially daunting if you have never programmed before. The following tips and tricks will help you become more proficient and comfortable in your coding experience.

 

1. Using Recorder

One of the best tools you can use while creating your VBA is to use the recorder button to record a Macro. This will autogenerate the VBA code for you. While you may need to make some small changes to this code to better suit your needs, it should guide you in the right direction and approach.

The best way to facilitate code generation is to record a different macro for each step and combine it into your final programme. Which brings us to the next tip …

 

2. Following a modular approach

Try to break-up your solutions into multiple steps and tackle them separately. Create separate sub routines for tasks which are repeated.

Need to open a different file every time? – make a small sub-routine which accomplishes this task.

Modular approach will do wonders to the ease of programming. This approach also reduces coding errors and makes your programme easier to understand.

 

3. Forcing declaration of Variables

Compared to some other programming languages like C, C++, Java, etc., VBA takes a lax approach to variables, in that, it allows the use of a variable without declaring them beforehand.

This approach while easy to use at first, frequently leads to coding errors. To force yourself to declare a variable before using it in a module, use the following command at top of your module:

                  Option Explicit

 

4. Disabling Excel Alerts

Some Excel actions require a confirmation on Excel in form of alerts – e.g., deleting a sheet with some data or formatting on it pops up an Excel confirmation alert. You can disable these alerts in VBA by using the following code before the coding area where you expect the alert/s:

                  Application.DisplayAlerts = False

Later, the alerts can be re-enabled with the command:

                  Application.DisplayAlerts = True

 

Hopefully, these tips will help you along your journey to VBA programming excellence. All the very best!

 

Contact Us

What is Remote Training?

Valued by Individuals

4.72 / 5
Over 26910 Reviews
Good session. Keen to learn more as I already knew some stuff. -MS Teams Brisbane
Karin - MS Teams, .
Very informative Would be good to have a booklet to review what was learnt in the course Steven to follow up on Power BI booklet for Melina Berthaux -MS Teams Brisbane
Melina - MS Teams, .
Good course, the afternoon was more relevant for me. The morning was more of a referesher -MS Teams Brisbane
Colin - MS Teams, .
happy with outcome. -MS Teams Brisbane
Wayne - MS Teams, .
Course was presented at a good pace and kept us interested. Steven was a good trainer and kept the group included and ensured we all kept up. -MS Teams Brisbane
Tammy - MS Teams, .
Presenter was clear and concise and knowledgeable -MS Teams Brisbane
Kevin - MS Teams, .
Good training with a knowledgeable trainer. -MS Teams Brisbane
Emma - MS Teams, .
Another great session, thanks to Jason for taking us through more functions of Power BI. I feel much more equipped to use the program for my work now. -Power BI Intermediate Brisbane
Bek - Power BI Intermediate, .
Good refresher -Excel Intermediate Brisbane
Shani - Excel Intermediate, .
Great class - I picked up some really good tricks and methods. -Excel Intermediate Brisbane
Melinda - Excel Intermediate, .
learnt a lot from Stuart, looking forward to the advance course -Excel Intermediate Brisbane
Andrea - Excel Intermediate, .
Great course, learned heaps! Good pace. Easy to follow online. -Power BI Intermediate Brisbane
Ashleigh - Power BI Intermediate, .
Found that the Intermediate course was great as a refresher but I did learn some great tips. -Excel Intermediate Brisbane
Suzanne - Excel Intermediate, .
Great building on the beginner course and some amazing things possible. Jason as always is excellent!!! Friendly, responsive to questions. Good resources to link into as well. Thanks very much -Power BI Intermediate Brisbane
Clea - Power BI Intermediate, .
This course was very good for me I learned a lot in the class today -Excel Beginner Sydney
Debra - Excel Beginner, .
I really enjoyed learning from Michael and will definately use what I have been taught. An excellent and approachable way to learn Excel. Thank you! -Excel Beginner Sydney
Marcia - Excel Beginner, .
Michael was very attentive and helpful. He kept pace and time for the course but was always happy to assist anyone needing help. The course itself was a great refresher and I am looking forward to returning for an Intermediate Excel course to further my skills. -Excel Beginner Sydney
George - Excel Beginner, .
Michael was very helpful and made it fun. -Excel Beginner Sydney
Melissa - Excel Beginner, .
I found this course informative and easy to understand -Excel Intermediate Melbourne
James - Excel Intermediate, .
Great course, thanks -Excel Intermediate Melbourne
Jake - Excel Intermediate, .

Trusted by Business

Procured by Government

Awards and Accreditations

Nexacu offices Australia

Follow us