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. Create Quiz Comment A ayushdey110 Follow 0 Improve A ayushdey110 Follow 0 Improve Article Tags : Excel Excel-VBA ExcelGuide Explore Excel FundamentalIntroduction to MS Excel5 min readDownload and Install MS Excel 2024/365 Edition4 min readExcel Spreadsheet4 min readWorkbooks in Microsoft Excel4 min readWorksheets in Excel4 min readDelete All Rows Below Certain Row or Active Cell in Excel5 min readRemove Hyperlinks in Excel6 min readHow to Use Fractions in Excel6 min readExcel FormattingData Formatting in Excel5 min readExpand Cells to Fit the Text Automatically in Excel3 min readExcel Date and Time Formats3 min readInsert a Picture in a Cell in MS Excel3 min readHow to Unhide and Show Hidden Columns in Excel: Step by Step Guide9 min readConditional Formatting in Excel8 min readApply Conditional Formatting Based On VLookup in Excel3 min readHow to Compare Two Columns and Delete Duplicates in Excel3 min readHow to Find Duplicate Values in Excel Using VLOOKUP3 min readExcel Formula & FunctionBasic Excel Formulas3 min readUse of Concatenate in Excel5 min readPercentage in Excel8 min readExcel LEFT, RIGHT, MID, LEN, and FIND Functions5 min readExcel IF Function10 min readExcel VLOOKUP Function12 min readDynamic Array Formulas in Excel2 min readCOUNTIF Function in Excel - Step by Step Tutorial7 min readHow To Use MATCH Function in Excel (With Examples)6 min readExcel Data Analysis & VisualizationHow to Sort by the Last Name in Excel?5 min readHow to Sort Data by Color in Excel?3 min readHow to Swap Columns in Excel: 3 Methods Explained8 min readSparklines in Excel8 min readPivot Tables in Excel3 min readHow to Sort a Pivot Table in Excel : A Complete Guide7 min readPivot Table Slicers in Excel5 min readData Visualizations in Power View3 min readChart Visualizations in Excel Power View8 min readTable Visualization in Excel Power View5 min readMultiple Visualizations in Excel Power View4 min readDynamic Excel Dashboards Using Picklists3 min readAdvanced ExcelHow to Use Solver in Excel3 min readPower Query â Source Reference as File Path in Cell2 min readHow to Create Relational Tables in Excel?4 min readHow to Import, Edit, Load and Consolidate Data in Excel Power Query?7 min readConnecting Excel to SQLite4 min readHandling Integers in Advanced Excel2 min readPower Pivot for Excel10 min readExcel Power Pivot - Managing Data Model6 min readTable and Chart Combinations in Excel Power Pivot3 min readExcel Data VisualizationAdvanced Excel - Chart Design4 min readHow to Create a Graph in Excel: A Step-by-Step Guide for Beginners8 min readFormatting Charts in Excel3 min readCreate a Waterfall Chart in Excel5 min readScatter and Bubble Chart Visualization in Excel5 min readCreate a Pie Chart in Excel5 min readHow To Create A Pictograph In Excel?3 min readHow to make a 3 Axis Graph using Excel?7 min readHow To Create a Tornado Chart In Excel?2 min readHow to Create Flowchart in Excel: Step-by-Step Guide6 min readExcel VBA & MacrosHow to Insert and Run VBA Code in Excel?2 min readVariables and Data Types in VBA Excel9 min readHow to Use the VBA Editor in Excel: Quick Guide 20247 min readVBA Strings in Excel8 min readVBA Find Function in Excel5 min readActiveX Control in Excel VBA3 min readMultidimensional Arrays in Excel VBA2 min readVBA Error Handling10 min readHow to Remove Duplicates From Array Using VBA in Excel?2 min readMacros In Excel With Examples10 min readAssigning Excel Macro to Objects3 min readHow to Enable Macros in Excel (2025): Step-by-Step Guide9 min readPower BI & Advance Features in ExcelPower BI - Tools and Functionalities5 min readPower BI - Data Sources and its type4 min readPower BI - How to Create a Report using Excel Data in Workspace4 min readData Analysis Expressions (DAX)6 min readPower BI - How to upload Excel Files to Dashboard?3 min read Like