Recording VBA Macros

I have intentionally left this until last, it is tempting to have this much earlier on though it doesn't always help to learn this method and it can be difficult to understand what have been recorded and what each part does. The macro record tool records the actions of the user - this includes selecting and moving the view. For more complicated applications this might not be the best approach.

To record a macro - click the record macro button on the bottom of the Excel application window.


You will be greeted with a input box asking for a macro name. For this example I will leave this blank though it is good practice to always give this a meaningful name as when you review this in the future the name "Macro 1" wont help.

At this point you are free to do whatever you want and then stop the recording with the same button that started in. In my example I selected a couple of cells and put numbers in for the values. 

When we open the VBA manager we can see a Sub routine called "Macro1" has been created and captured what we did.

Note that in this example it has captured the moving of the window. It also assigns the value of a cell with two commands. In the tutorial VBA with Excel we only needed one command to write to a cell.

Not everything will be recorded which may cause unwanted behaviour and also extra information will be recorded. But on the other hand this tool does allow you to learn new commands - just use with caution. 





Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.



Must Read Articles


VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.
Installing VBA and First Program - What do you need to start using visual basic application VBA.