VBA Subroutine in Excel - How to Call Sub in VBA? Last Updated : 29 Oct, 2022 Comments Improve Suggest changes Like Article Like Report When a specified action is performed on a worksheet with the help of a collection of code known as a VBA Subroutine. It also helps to read an external file, also it can open other applications from Excel. A large piece of code can be broken into small parts so that we can manage it easily. Let's learn why to use submarines: Converts large piece of codes into small parts so that the computer ignores all kind of complexities that arises because of large codesReusability of code suppose we in a program have to access the database frequently so instead of writing the code again and again we can create a function to access the databaseSubroutines are self-documenting functions which means a coder can easily say what the program does by looking into the name of the function Naming Rules of SubroutinesIt can start with a letter or an underscore but it cannot start with a number or a special character.It cannot contain any space in the name.The name of the subroutine cannot be a keyword like Private, Sub, End, etc. Syntax Private Sub function_name( ByVal arg1 As String, ByVal arg2 As String) End Sub Syntax Explanation Code Action "Private Sub function_name(...)"Private is the keyword which is representing the scope of the subroutine. The name of the subroutine i.e function_name will be mentioned after the Sub keyword which starts the body of the subroutine."ByVal arg1 As String, ByVal arg2 As String"Two parameters of data type String are declared whose names are arg1 and arg2."End Sub"The body of the subroutine is ended.How to call Sub in VBA? Step 1: Select the developer tab and click Insert drop-down list from the control box. Step 2: Choose the command button from ActiveX Controls Box. Step 3: Draw the command button in the excel sheet. Step 4: Press Alt + F11 to open the VBA code. Step 5: Write the following subroutine with the name "display" which will display a name in the message box once its function gets called. Step 6: To call the subroutine we need to right-click on the command button and then select view code. Step 7: Write the following code to call the display function by clicking the command button. The following code displays the overall code of the program. Comment More infoAdvertise with us Next Article VBA Subroutine in Excel - How to Call Sub in VBA? A ayushdey110 Follow Improve Article Tags : Excel Excel-VBA ExcelGuide Similar Reads 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 Set Variable to Cell Value in Excel VBA? Adding data to the worksheet is often done and it is essential to learn how to set variable to cell value in excel VBA. There can be instances when you want to add the same data to your worksheet. This task could easily be achieved with the help of Excel VBA variables. You can assign your cell value 5 min read 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 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 use If-Else Statement in Excel VBA? VBA in Excel stands for Visual Basic for Applications which is Microsoft's programming language. To optimize the performance and reduce the time in Excel we need Macros and VBA is the tool used in the backend. In this article, we are going to learn how to use the If Else statement in Excel VBA. Impl 3 min read How to Use Select Case Statement in Excel VBA? VBA in Excel stands for Visual Basic for Applications which is Microsoft's programming language. To optimize the performance and reduce the time in Excel we need Macros and VBA is the tool used in the backend. In this article, we are going to discuss how to use Select Case Statement in Excel VBA. Se 10 min read How to Calculate Running Total in Excel? Excel is a tool widely used by professionals for financial data or trend analysis but can be used for different purposes. It is used for various data visualization purposes. It simplifies data management and data evaluation which uses spreadsheets for managing, storing, and visualizing large volumes 2 min read How to Mask Password in VBA Excel Input Box? A combination of integers, strings of characters, or other symbols is used to verify the identity of a user during the authentication process so, that they can access the system. But a password should always remain in a hidden format to prevent it from shoulder spying. Shoulder spying is a practice 2 min read How to use If-Else-If Statement in Excel VBA? In this article, we are going to look into how to use the If Else If statement in Excel VBA using a suitable example. Implementation : In the Microsoft Excel tabs, select the Developer Tab. Initially, the Developer Tab may not be available. The Developer Tab can be enabled easily by a two-step proce 3 min read How to Run Code from a Module in Excel VBA 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 lear 4 min read Like