In our preceding articles, we have demonstrated the easiest way to create simple macros using the macro recorder. To make complex macros, you have to write a program using VBA. To save time in developing your macro, you can combine both: recording and manually code entry.
Before you can start writing your own VBA code, you must have a good understanding of these topics: objects, properties, and methods. It is also necessary to be familiar with common programming constructs, such as looping and If-Then statements.
In this and next some articles, we shall introduce you to VBA programming that is essential to write VBA macros. It is not a complete instructional guide. We shall cover all the topics of VBA and advanced spreadsheet application development on another devoted page.
The basics: Entering and editing code
Before you can enter a code, you must insert a VBA module into the workbook. If the workbook already has a VBA module, you can use the existing module sheet for your new code.
Follow these steps to insert a new VBA module:
- Press Alt+F11 and the VB Editor window will be activated. The Project window displays a list of all open workbooks and add-ins.
- In the Project window, find out and select the workbook you’re working in.
- Choose Insert ➪ Module. VBA will insert an empty and new module into the selected workbook. The code window will display the Module.
1) After selecting the destination (here the workbook) 2) choose Insert->Module 3) Code window will be displayed.
A VBA module is like a text editor. It is displayed in a separate window (Code window). You can select the text, copy and cut text, insert and paste the text into it, move through the sheet, and so on.
Happy Excelling 🙂