Excel VBA
Introduction To VBA: Macros And Automation Part 1
A Final Note & Activity
A Final Note
We have gone from no knowledge of VBA, to being able to create an If statement with variables pulling data in from our spreadsheets. This is not only great first steps, but with it you have the foundation necessary to begin to explore further. Practice creating variables, using them in logical comparisons or mathematic equations, and outputting them via a message box.
It is important to become comfortable with the steps of defining and setting variables, as well as exploring the different operations you can perform on them. For text values, see what happens when you try to join multiple strings together using the operators which exist in VBA.
Aside from Excellency.ca, the Microsoft website holds all the information you could ever hope to collect in terms of listing out and describing the various keywords, operators, data types, and other pieces of the puzzle that makes up VBA. For those who want to continue researching the keywords and operators discussed in this guide THIS is a great place to start.
Subsequent VBA guides will provide deeper insights into the world of coding within Excel, more keywords, more logical and iterative statements, and more complexity.
Practice makes perfect, and while there is no such thing as a perfect programmer, we can always strive to achieve greatness!
An Activity
This activity will be more of a challenge and less of a guided experience. You will be given a task which you can accomplish any way you see fit. There are many ways in which you can solve this problem, and we will be providing the code for one way to do so. The method we will be using takes into account all the things which we have learned in this guide.
Here is the challenge:
Create a subroutine that returns the absolute (always positive) difference between two numbers. Note that these numbers should be able to have decimal values! Post the result to a message box which says “The absolute difference is exactly” followed by the difference. To standardize the cell references, cell C1 and D1 are to be used as inputs for both values. One exception is that if the values are equal, the message “There is no difference between the values” should be displayed.
Our answer code is available in the download package that came with this guide.
Good luck and happy coding!
And that’s it for this one! Compare your final outputs for final activity with me by downloading the results text file HERE.