I found an Excel VBA Code on the internet.
How do I add it to my Excel file?
O.K. So first I want to share a bit of information on What is VBA code.
For the actual steps please scroll down.
What is VBA Code in excel?
VBA is stands for Visual Basic for Applications. It is a programming language that was developed for Microsoft Applications by Microsoft.
It is essentially the programing language behind everything we do in excel.
Imagine that as you do something in excel. Select a Cell, or apply a filter a magical pixie in the background writes a piece of code for everything you do. VBA is describing your actions as a programming language.
This code called VBA or VBA macro.
We will actually be able to see this when we record a macro!
O.K. so there is a VBA code what’s the big deal about it?
The “big deal” is that we can also write our own code and play it just like playing a movie.
The backend of MS Excel is called Visual Basic Editor.
This is where we need to paste in our code.
The Visual Basic Editor
(Where we have to paste in the code)
By default the Developer menu where the Visual Basic Editor lives is not visible on the ribbon.
you can reach the VBA Editor with the Ctrl+F11 Keyboard shortcut.
Below you can see how to unhide the developer tab by right clicking on the ribbon, and selecting Customise Ribbon
Where to paste the code I found?
Most of the code you find on the internet will have to be pasted in to two places in the VBA Editor.
On the left you can see the workbooks and Addons that are open/loaded
Underneath your workbook Highlighted in Bold There is This Workbook
If you doubleclick this on the right you will see the editor window that’s where the code goes.
In the gif below I will show you the second option then we will discuss the difference.
The Second option: Add a Module
This Workbook and Module
What is the difference?
In the This Workbook section can be triggered by various workbook functions.
The most common triggers are:
- run the code on opening the workbook
- run the code before someone closes workbook
- If something changes in a range in a worksheet
- If someone clicks in to a cell/range on a worksheet
The other place you put code, is in a Module.
A module can be reached from all part of the workbook.
More of a general section for codes.
Don’t forget to save your workbook as .xlsm!
Once you added code to a workbook, you need to save it as some kind of macro enabled workbook.
Come and visit us.
Come and visit excelangel on Facebook to find and join the growing community of true office workers.
Oh, I almost forgot.
Drop us a like while you there…