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 23083 Reviews
The course provided a great base to continue my learning with Power BI. -Power BI Beginner Melbourne
Chris - Power BI Beginner, .
John was direct and concise with his delivery. As a Supervisor I am now more prepared to request reports of the types I require . Long day but excellent information and paced well. Thank you -Power BI Beginner Parramatta
Glenda - Power BI Beginner, .
Very interesting course. John was great but the course was a lot to take in one day, maybe it should be split into 2 sessions over 2 days. -Power BI Beginner Melbourne
kaan - Power BI Beginner, .
Very informative and easy to follow. Patient and communicated well Now have a better understanding of how to set up Power BI reports. -Power BI Beginner Melbourne
Melanie - Power BI Beginner, .
Steven has a great knowledge and great present skill for the day. the course was well designed. satisfied with everything. Thank you -Power BI Beginner Brisbane
Megan - Power BI Beginner, .
Hands on, enjoyable training. Thank you Steven -Power BI Beginner Brisbane
Catalina - Power BI Beginner, .
Good intro into the world of Power BI. Hope to be able to put it into practice straight away -Power BI Beginner Brisbane
Raelene - Power BI Beginner, .
Useful course and excellent trainer -Power BI Beginner Brisbane
Rajesh - Power BI Beginner, .
Course was well structured and paced. Steven was a knowledgeable instructor. -Power BI Beginner Brisbane
Brianna - Power BI Beginner, .
Really good fun and informative with Steven, as always. -Power BI Beginner Brisbane
James - Power BI Beginner, .
Thank you! See you again for intermediate and advanced -Excel Beginner Brisbane
JULIE - Excel Beginner, .
Jason was an awesome instructor that had my full attention for the duration of the course. I really enjoyed the hands on experience & being able to follow along with my own laptop. Thank you for an amazing course! -Excel Beginner Brisbane
Emma - Excel Beginner, .
Well delivered class! Definitely learnt a lot and had a laugh which was good. Thank you Jason, you're an excellent teacher. -Excel Beginner Brisbane
Layla - Excel Beginner, .
Very much enjoyed the course, easy to understand and follow, I feel like I have a better understanding of the program now so thank you Jason! -Excel Beginner Brisbane
Serena - Excel Beginner, .
Excellent course -Excel Beginner Brisbane
Nahan - Excel Beginner, .
AMAZING! So grateful I completed this. See you for intermediate and advanced soon :) -Excel Beginner Remote Online
JULIE - Excel Beginner, .
made sense of what i have been trying to achieve since moving into an office environment -Excel Beginner Brisbane
Joseph - Excel Beginner, .
Excellent trainer -Excel Beginner Brisbane
Peter - Excel Beginner, .
Really helpful - good teacher -Excel Beginner Brisbane
Martin - Excel Beginner, .
Great session with Jason as always -Excel Advanced Remote Online
Rebecca - Excel Advanced, .

Trusted by Business

Procured by Government

Map of Australia