What is Procedure in VBA?

The procedure is basically a group of computer code that performs some action. There are basically three types of Procedure in VBA.

Examples

(A).     Public Sub Procedure1( )

           End Sub

(B).     Private Sub Procedure2( )

           End Sub

(C).     Public Function Functions1( )

           End Function

(D).     Private Functions2( )

           End Function

what is procedure

  1. Sub Procedure. A sub procedure of group of VBA statement that performs on the action. Sub Procedure is by default Public so we can call Sub procedure into another module. If we mention as Private Sub so we cannot call Sub Procedure into another module.

 

  1. Function Procedure. A function procedure is a group of VBA statement that performs on calculation. Function procedure always returns value. You can create a custom function in excel. Function Procedure is by Default Public So we can call Function Procedure into another module. If we mention as Private Function so we cannot call Function Procedure into another module.

 

  1. Property Procedure. A property procedure is a group of VBA statement that is used to create a new object and new property.

 

What is Procedure in VBA?

Naming Sub and Function Procedure in VBA.

There is some rule for Procedure Naming. You can use Letter, Number and some punctuation characters.

  1. When we write a name for Procedure, a name should be Alpha-Numeric/Alpha.

            Valid – ABCD123

            Invalid – 12ABCD

  1. We have to avoid space between words while writing Procedure name.

            Invalid – First Code

  1. We have to avoid special character between word except (_Underscore).

            Valid – First_Code

            Invalid – First#Code

  1. We have to avoid reserve word/Keyword/System Defined Word for procedure naming

            Range, Sub, Function, Integer

  1. We cannot write more than 255 characters for procedure naming

 

Note 

We write procedure more than one into the same module each procedure name must unique if we write duplicate procedure name into the same module and we run a procedure then we get an error as shown in below picture.

what is function procedure

What is Variable in VBA?