Return to VBA Code Examples

VBA Call / Run Sub From another Subroutine

This tutorial will teach you how to call a sub procedure from within another sub procedure in VBA

It is very useful to write code that can be used repetitively, and called from multiple sub procedures in your project – it can save an enormous amount of time and makes the VBA code far more efficient.

Running a Sub Procedure from another Sub Procedure

Consider the 3 Sub Procedures below:

If we run the Sub Procedure – TestRoutine – it will call RunRoutine1 and RunRoutine2 and 2 message boxes will appear.

vba run subs

There is no limit to the number of Sub Procedures you can call from another Sub Procedure.

Using the Call Statement

You can also use the Call Statement in front of the procedure name, to make your code easier to read.   However, it has no effect whatsoever on how the code is run or stored.

vba run subs call

Calling a Sub with Arguments

It is also possible to call a sub with arguments

vba run sub parameters

Calling a Sub with Named Arguments

If you name your arguments, you don’t have to pass them in the same order to your sub routines.

vba run sub multi parameters

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!