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.8/5
Over 25129 Reviews
Some very helpful tips, definitely things I can use in the future -Word Advanced Brisbane
Millie - Word Advanced, .
Very informative and engaging. Good teacher -Excel Intermediate Brisbane
Alisha - Excel Intermediate, .
was informative and well done -Excel Intermediate Brisbane
Sola - Excel Intermediate, .
thank you great course and facilitator was great -Excel Intermediate Brisbane
Luke - Excel Intermediate, .
very useful. -Excel Intermediate Brisbane
Jennifer - Excel Intermediate, .
Very clear and helpful. Good pace also. Well structured. -Excel Intermediate Brisbane
Aria - Excel Intermediate, .
This course was great. I knew very little about VBA prior to attending and Michael was clear and built knowledge so well that I feel confident attempting to apply this in real work situations. A highly recommended course. -Excel Macros/VBA 2 Day Parramatta
Mary - Excel Macros/VBA 2 Day, .
This course was amazing. Michael was such an engaging teacher and kept the class so informative and so easy to follow. We had a great time learning the content of this course and we loved the small class we were in. We could ask a lot of questions and enjoy the whole course at the same time. This was one of many courses I have attended with Nexacu and all the teachers are great. Michael is my favourite. 5 Stars from me from all perspectives !!! -Excel Macros/VBA 2 Day Parramatta
Jacqueline - Excel Macros/VBA 2 Day, .
Moved a bit quicker than the beginner but showed good examples of what you can do. I certainly need to go away and practice with some real data to apply what I have learned today. Many thanks -Power BI Intermediate Adelaide
Merrin - Power BI Intermediate, .
Thanks for the help! -Power BI Intermediate Adelaide
Bradley - Power BI Intermediate, .
Brilliant - learnt so much. Many thanks Jagg -Power BI Intermediate Adelaide
John - Power BI Intermediate, .
was able to learn new formulas and functions that will help me in the future. -Power BI Intermediate Adelaide
Estelle - Power BI Intermediate, .
Learnt a lot on how to manipulate and clean up data. Learnt to better manage permissions to data. Learnt more on the date functions, though still don't know how to calculate current week/previous week comparisons. -Power BI Intermediate Melbourne
Kristina - Power BI Intermediate, .
Learnt many items with Power Query and DAX, along with row level security which is of particular interest with the types of personnel reports I will need to build. -Power BI Intermediate Melbourne
Kylie - Power BI Intermediate, .
Excellent content, great teacher. Thank you! -Excel Intermediate Melbourne
Linda - Excel Intermediate, .
Steven was incredibly helpful in training us. He took the time to understand our professional roles and relate what we were learning to our day to day tasks. He was patient and professional. Thank you! -Word Intermediate Brisbane
Alison - Word Intermediate, .
I have enjoyed it and learned many tips. -Word Intermediate Brisbane
Kristian - Word Intermediate, .
This was great! -Word Intermediate Brisbane
Courteney - Word Intermediate, .
Well-paced and very informative training. Trainer is very knowledgeable and helpful with any questions. -Power BI Intermediate Brisbane
Emily - Power BI Intermediate, .
Great course. Jason was very clear and easy to understand. Learnt a lot in one day. Thanks! -Power BI Intermediate Brisbane
Ben - Power BI Intermediate, .

Trusted by Business

Procured by Government

Awards and Accreditations

Map of Australia

Follow us