Excel VBA Subroutine: How to Call Sub in VBA with Example - Shikshaglobe

Content Creator: Vijay Kumar

What is a Subroutine in VBA?

A Subroutine in VBA is a piece of code that plays out a particular errand depicted in the code however doesn't return an outcome or a worth. Subroutines are utilized to separate huge bits of code into little sensible parts. Subroutines can be reviewed on numerous occasions from any place in the program.

Suppose you have made a UI with text boxes for tolerating client input information. You can make a subroutine that gets the items free from the text boxes. A VBA Call Subroutine is proper in such a situation since you would rather not return any outcomes.

Calling a Subroutine in VBA:

1.     Define the Subroutine:

ยท         First, define the subroutine that you want to call. A subroutine is a block of code enclosed between Sub and End Sub statements. It should have a unique name and, optionally, parameters if it requires input values.

Call the Subroutine:


To call a subroutine, use its name followed by parentheses. If the subroutine requires parameters, provide them within the parentheses.

Why Call Subroutines?

Calling subroutines is a critical practice in VBA for several reasons:

  • Modular Code: Subroutines allow you to break your code into smaller, manageable segments, enhancing readability and maintainability.
  • Reuse: You can call the same subroutine from multiple parts of your code, eliminating redundancy and promoting code reusability.
  • Organization: Subroutines help organize your code by isolating different functionalities into distinct blocks.
  • Readability: Calling subroutines can make your primary code more concise and comprehensible by abstracting complex operations.
  • Testing: You can test individual subroutines independently, simplifying the identification and resolution of issues.

    Click here for details

Why use Subroutines

Break code into little sensible code: A typical PC program has a great many source code lines. This presents intricacy. Subroutines assist with taking care of this issue by separating the program into little sensible lumps of code.

Code reusability. Suppose you have a program that requires getting to the data set, practically every one of the windows in the program should connect with the data set. Rather than composing separate code for these windows, you can make a capability that handles all data set communications. You can then call it from whichever window you need.

Subroutines and capabilities are self-archiving. Suppose you have the capability to calculate loan interest and another that says connect to database. Simply by taking a gander at the name of the subroutine/capability, the software engineer will actually want to determine what the program does.

Rules of naming Subroutines and Functions

To utilize subroutines and capabilities, there are set of decisions that one needs to follow.

A subroutine or VBA call capability name can't contain space

An Excel VBA Call Sub or capability name ought, to begin with a letter or a highlight. It can't begin with a number or an exceptional person

A subroutine or capability name can't be a catchphrase. A catchphrase is a word that has extraordinary significance in VBA. Words like Private, Sub, Function, and End, and so forth are instances of catchphrases. The compiler involves them for explicit errands.

VBA Subroutine Syntax

You should empower the Developer tab in Excel to track with this model. In the event that you don't have the foggiest idea how to empower the Developer tab then, at that point, read the instructional exercise on VBA Operators

Experience the difference

The accompanying subroutine acknowledges the first and last name and shows them in a message box.

Child Care Management Course Admission

Presently we will program and execute this Sub Procedure. Let's see this.

Experience the difference

The most effective method to Call Sub in VBA

The following is a bit-by-bit process on the most proficient method to Call Sub in VBA:

Plan the UI and set the properties for the client controls.

Add the subroutine

Compose the snap occasion code for the order button that calls the subroutine

Test the application

Stage 1) User Interface

Plan the UI as displayed in the picture beneath.

The most effective method to Call Sub in VBA

Set the accompanying properties. The properties that we are setting:

Your connection point ought to now look as follows.

VBA Functions and Subroutine

Stage 2) Add subroutine

See also here -->>

Press Alt + F11 to open the code window

Add the accompanying subroutine


A subroutine is a piece of code that plays out a particular errand. A subroutine doesn't return a worth after execution

Subroutines offer code reusability

Subroutines assist with separating huge pieces of code into little sensible code.

Read More :

Workflows In Informatica
VBA Arithmetic Operators
Session Objects in Informatica
Workflow Monitor in Informatica

Featured Universities

Mahatma Gandhi University

Location: Soreng ,Sikkim , India
Approved: UGC
Course Offered: UG and PG

MATS University

Location: Raipur, Chhattisgarh, India
Approved: UGC
Course Offered: UG and PG

Kalinga University

Location: Raipur, Chhattisgarh,India
Approved: UGC
Course Offered: UG and PG

Vinayaka Missions Sikkim University

Location: Gangtok, Sikkim, India
Approved: UGC
Course Offered: UG and PG

Sabarmati University

Location: Ahmedabad, Gujarat, India
Approved: UGC
Course Offered: UG and PG

Arni University

Location: Tanda, Himachal Pradesh, India.
Approved: UGC
Course Offered: UG and PG

Capital University

Location: Jhumri Telaiya Jharkhand,India
Approved: UGC
Course Offered: UG and PG

Glocal University

Location: Saharanpur, UP, India.
Approved: UGC
Course Offered: UG and PG

Himalayan Garhwal University

Location: PG, Uttarakhand, India
Approved: UGC
Course Offered: UG and PG

Sikkim Professional University

Location: Sikkim, India
Approved: UGC
Course Offered: UG and PG

North East Frontier Technical University

Location: Aalo, AP ,India
Approved: UGC
Course Offered: UG and PG