Naming Rules of Sub Procedure

  • It 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 subprocedure cannot be a keyword like Private, Sub, End, etc. 

Syntax

Sub name_procedure ()

End Sub

Let’s discuss different ways to create Sub Procedure:

Sub Procedure in Excel VBA

A Sub Procedure is an action that is written in VBA code. It starts with a Sub statement and ends with an End Sub statement. It is used to manipulate the data in an Excel sheet which includes a table present in an Excel sheet or a pivot table present in the Excel sheet. The name of the procedure should be followed by parentheses. Let’s learn why to use sub procedure:

  • Converts large piece of codes into small parts so that the computer ignores all kind of complexities that arises because of large codes
  • In a program, we have to access the database frequently. In this case, instead of writing the code again and again we can simply create a function to access the database. Reusability of code can be done.

Similar Reads

Naming Rules of Sub Procedure

It 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 subprocedure cannot be a keyword like Private, Sub, End, etc....

Creating a Sub Procedure with Macro

Step 1: Select View in the Ribbon then click on Macros to select Record Macro...

Creating a Sub Procedure in VBA window

Step 1: Press Alt+F11 in the main Excel window to the VBE window....

Creating a Button to Run Macro

Step 1: Select the developer tab and click Insert drop-down list from the control box....

Types of VBA Subroutine

There are two types in Sub procedures:...