How to Run Code from a Module in Excel VBA Last Updated : 06 Sep, 2023 Comments Improve Suggest changes Like Article Like Report VBA Macro is for developers. In Excel, the macro is a piece of code written in VBA and VBA is Microsoft's programming language, it stands for Visual Basic for Applications. The module is a file with a .bcf extension that stores the code written in the Visual Basic for Applications editor. Let's learn, how to run a code from a module in Excel VBA. Run a code from the Module in Excel VBAStep 1: Go to the Developer Tab, Under the code section you will find Visual Basic. Now click on Visual Basic. Step 2: Microsoft Visual Basic for Applications(VBA) dialogue box appears. In the Menu bar, go to Insert Tab, and click on Module. Step 3: A Module named Module1 is created under the VBA project. Step 4: Write the code you want to run in Microsoft excel. For example, a message box will appear stating "Learning geeks for geeks". Step 5: In the Tools bar. Click on the run button. You can also press F4(Fn + f4) on your keyboard to run the module code. Step 6: The code pauses and the Microsoft VBA editor minimizes and a message box appears in the MS Excel worksheet. Click Ok. The code resumes and the Microsoft VBA editor maximizes again. Scope of Module in VBA The scope of the module in VBA is workbook level. You can use the written modules in different worksheets. You have created a module named module1 in shee1 above. A sub-procedure named geeksforgeeks() is also created. We will use this procedure to check the scope of a module in VBA. Following are the steps: Step 1: Click on the plus and a new worksheet named sheet2 is created. Step 2: Go to the Developer tab, and click on Macros. Step 3: A dialogue box named Macro appears. In the macro name, you will find a procedure name geeksforgeeks(). This was the procedure that we wrote in sheet1 of this workbook. This proved that the scope of the module is workbook level. Select it, and click on Run. Step 4: The code written in the module1 sub procedure gets executed. A dialogue box appears. Comment More infoAdvertise with us Next Article How to Run Code from a Module in Excel VBA gautamgoel962 Follow Improve Article Tags : Excel Geeks-Premier-League-2022 Excel-VBA ExcelGuide Similar Reads How to Delete a Module in Excel VBA? Have you ever seen a text file in a notepad or a source code file in visual studio code? These all are just basic files where you can write some code or information. Similarly, we have modules in excel, each module has its code window, where you can write some code and allow it to automate your repe 3 min read How to Insert and Run VBA Code in Excel? In Excel VBA stands for (Visual Basic for Application Code) where we can automate our task with help of codes and codes that will manipulate(like inserting, creating, or deleting a row, column, or graph) the data in a worksheet or workbook. With the help of VBA, we can also automate the task in exce 2 min read How to Add a Comment in a VBA in Excel? VBA Macro is for developers. Macro is a piece of code written in VBA. VBA is Microsoft's programming language and it stands for Visual Basic for Applications. Let's see how to set up our VBA Macro and how to add comments in a VBA in Excel. VBA Macro Excel is a very advanced tool that contains thousa 4 min read How to Enable & Run a Macro in Excel? 6 Ways We can record a macro in Excel or write from scratch in VB Editor. Excel provides different options to run a macro. In this article, we explore four different approaches to running a macro in an Excel application. Even while executing an Excel macro is a straightforward process for seasoned users, i 5 min read How to Read Data From Text File in Excel VBA VBA Program to read a Text file line by line (Sales Data) and place it on a worksheet It provides a concise introduction to the process of importing data from text files into Microsoft Excel using Visual Basic for Applications (VBA). This introductory article serves as a starting point for individua 5 min read How to Use For Next Loop in Excel VBA? If you are familiar with the programming you must have an idea of what a loop is, In computer programming, a loop is a sequence of statements that are repeated until a specific condition is satisfied. In Excel VBA the "For Next" loop is used to go through a block of code a specific number of times. 4 min read How to Create a User Defined Function in Excel VBA A function is a collection of code. Â As a developer, we very often need a custom function (User-defined function) in our projects. These functions can be used as normal functions in Excel. These are helpful when the existing functions are not enough. In such cases, the user can create his own custom 6 min read How to Round With Doubles in Excel VBA The round function is used to round the floating numbers to a particular decimal value. Rounding a number, where it has a long decimal value will give a good balance between accuracy and readability. It also helps in calculation and also to get a precise result. In real life, it is useful in doing m 5 min read How to Debug a User Defined Function in Excel VBA Debugging a User Defined Function (UDF) in Excel VBA can feel like a detective mission where you search for clues to fix issues in your code. When a custom function doesnât deliver the expected results, it can disrupt your workflow and lead to frustration. Fortunately, debugging tools in VBA make it 9 min read How to Find the Last Used Row and Column in Excel VBA? We use Range.SpecialCells() method in the below VBA Code to find and return details of last used row, column, and cell in a worksheet. Sample Data: Sample Data Syntax: expression.SpecialCells (Type, Value) Eg: To return the last used cell address in an activesheet. ActiveSheet.Range("A1").SpecialCel 2 min read Like