WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Free Tutorials
  • Certification Courses
  • Excel VBA All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA Call Sub

VBA Call Sub

What is Call Sub in VBA?

We can execute all the sub-procedures of the same module in a single subroutine, and the process of executing them in a single VBA subroutine called “Call Sub.”

In some of the cases, we may need to write a huge amount of code to and writing them in a single macro creates lots of problems while debugging the code. At the start, everybody tends to do this purely because of the lack of knowledge on the “Call Sub” method.

It is not a good practice of keeping all the codes in a single subprocedure. We need to break them into multiple sub procedures to simplify the code.

VBA Call Sub

How to Call Subroutine in Excel VBA?

Running the excel macro from one procedure to another make life easier for purely on the basis of saving a lot of time while running as well a while debugging the code in case of any error.

You can download this VBA Call Sub Excel Template here – VBA Call Sub Excel Template

Code:

Sub Code_1()

  Range("A1").Value = "Hello"

End Sub

Sub Code_2()

  Range("A1").Interior.Color = rgbAquamarine

End Sub

VBA Call Sub Example 1

In the above image, we have two subprocedures. The first one is “Code_1,” and the second one is “Code_2”.

In the first VBA call subcode, I have just written a code to insert a value to the cell A1 as “Hello.” In the second sub procedure, I have written the code to change the interior color of the cell A1 to “rgbAquamarine.”

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

Now I will run the first code, i.e., “Code_1”.

VBA Call Sub Example 1-1

Now I will run the second code, i.e., “Code_2”.

VBA Call Sub Example 1-2

Here I have executed the code times.

By using the VBA “call Sub,” we can execute both the subprocedure in a single macro only. We just need to add the word “Call,” followed by a macro name.

Look at the below graphic picture.

VBA Call Sub Example 1-3

I have mentioned the code as “Call Code_2” in the first subprocedure only. Now to understand, let’s run the code line by line. Press the F8 key. It will highlight the macro name.

VBA Call Sub Example 1-4

Press the F8 key one more time it will jump to the next line.

VBA Call Sub Example 1-5

The yellow-colored line shows the highlighted code is about to execute if we press the F8 key one more time. Press the F8 key now.

Example 1-6

As we can see, it has inserted the word “Hello” to the cell A1. Now the “Call Code_2” line has been highlighted.

“Call Code_2” has the task of changing the interior color of the cell A1 and the word “Call Code_2” will execute this code from the actual sub procedure only.

But press the F8 key to see the magic.

Example 1-7

It has jumped to the mentioned subprocedure name. Press the F8 key once again.

Example 1-8

Now the actual task line highlighted, to execute this press F8 key one more time.

Example 1-9

Like this, we can execute many sub-procedures from one subprocedure by calling the subprocedure by their name with the word “Call.”

Note:

  • We can execute the macro of another sub procedure without using the word “Call” but just by mentioning the macro name itself.
  • This is not the best practice because if the macro sub procedure contains parenthesis that you want to execute, then the “Call” word is mandatory.
  • In my personal opinion, always use the word “Call” because it is just a 4 letter word which allows others to understand the code correctly.

Recommended Articles

This has been a guide to Excel VBA Call Sub. Here we learn how to Call Subroutine in excel VBA along with practical examples and a downloadable excel template. Below are some useful excel articles related to VBA.

  • Excel VBA Tutorial for Beginners
  • VBA End
  • Today in VBA
  • Subscript Out of Range in VBA
7 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA Call Sub Excel Template

New Year Offer - VBA Training Course (6 courses, 35+ hours video) View More