Writing VBA code in Excel: Entering and Editing code

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:

  1. Press Alt+F11 and the VB Editor window will be activated. The Project window displays a list of all open workbooks and add-ins.
  2. In the Project window, find out and select the workbook you’re working in.
  3. Choose Insert ➪ Module. VBA will insert an empty and new module into the selected workbook. The code window will display the Module.
Writing VBA code in Excel: Entering and Editing code

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 🙂

Read More



Hello! Welcome to my Excel blog! It took me some time to be a fan of Excel. But now I am a die-hard fan of MS Excel. I learn new ways of doing things with Excel and share them here. Not only how-to guide on Excel, but you will get also topics on Finance, Statistics, Data Analysis, and BI. Stay tuned! You can checkout my courses at Udemy: https://www.udemy.com/user/exceldemy/

We will be happy to hear your thoughts

Leave a reply