To run one VBA Sub from another in Excel, you simply call the target Sub by its name, optionally passing arguments if needed. No special setup is required beyond having both procedures in accessible modules within the same VBA project. This technique helps organize code, reduce duplication, and build modular macros.

What You'll Need

  • Microsoft Excel installed (Excel 2010 or later, including Microsoft 365)
  • Basic familiarity with VBA (Variables, Sub procedures, module structure)
  • Developer Tab enabled in Excel (to access the VBA editor)
  • Two or more Sub procedures: one calling procedure (caller) and one or more called procedures (callee)

Step-by-Step

  1. Open Excel and press Alt + F11 to launch the Visual Basic for Applications (VBA) editor.
  2. In the VBA editor, go to Insert > Module to create a new standard module if one doesn’t already exist. Repeat to create a second module if you want to separate concerns, though modules in the same project can call each other regardless of location.
  3. Define the first Sub (the caller) that will trigger the second. For example, in Module1, type:
    Sub CallerSub()
        MsgBox "Starting CallerSub..."
        CalledSub
        MsgBox "CallerSub completed."
    End Sub
    This Sub shows a message, runs CalledSub, then shows another message.
  4. Define the second Sub (the callee) in the same or another module. In Module2, type:
    Sub CalledSub()
        MsgBox "Running CalledSub from CallerSub."
    End Sub
    Note: CalledSub must be declared as Public or have default (public) scope. In standard modules, procedures are public by default unless prefixed with Private.
  5. Save your workbook as a macro-enabled file (.xlsm) by going to File > Save As > Browse, then selecting Excel Macro-Enabled Workbook (*.xlsm) from the file type dropdown.
  6. Return to Excel. Press Alt + F8 to open the Macro dialog box. Select CallerSub and click Run. You should see the two message boxes in sequence, confirming that CalledSub executed inside CallerSub.

Common Mistakes

  • Calling a private procedure: If CalledSub is declared as Private Sub CalledSub() in a standard module, Excel will throw a compile error: “Sub or Function not defined.” Only use Private if calling from within the same code module.
  • Mismatched procedure names: Typos in the call (e.g., CalleSub instead of CalledSub) cause the same compile error. VBA is case-insensitive, but spelling must match exactly.
  • Calling from a different project: Procedures in a different workbook or VBA project (e.g., an add-in) cannot be called directly by name unless you set a reference or use Application.Run with the workbook name.
  • Forgetting to declare the procedure: If you delete or rename CalledSub after writing the call, Excel won’t detect the issue until runtime or compile time, depending on settings.
  • Using Call incorrectly: While Call CalledSub works, CalledSub without parentheses is preferred and more idiomatic in modern VBA. Don’t use parentheses around arguments unless using Call syntax.

Tips

  • Group related logic: Keep helper Subs in separate modules (e.g., modFormatting, modDataValidation) and call them from a main driver Sub like RunAllChecks.
  • Pass arguments when needed: If CalledSub requires input, define parameters and pass them:
    Sub CallerSub()
        CalledSubWithArgs "Sheet1", 10
    End Sub
    
    Sub CalledSubWithArgs(wsName As String, rowCount As Long)
        Sheets(wsName).Cells(rowCount, 1).Value = "Done"
    End Sub
    Note: Arguments must match in number, order, and data type.
  • Use Application.Run for dynamic calls: If the procedure name is stored in a variable, use:
    Dim procName As String
    procName = "CalledSub"
    Application.Run procName
    This is useful for building configurable macro pipelines.
  • Debug step-by-step: Press F8 in the VBA editor to step into each line, verifying that control transfers correctly to the callee.
  • Avoid naming conflicts: If multiple modules have a Sub named Main, qualify the call with the module name: Module1.Main, or rename to be unique.

Troubleshooting

If your Sub call fails to execute, follow these checks:

  1. Compile the project: In the VBA editor, go to Debug > Compile VBAProject. This reveals syntax or reference errors before runtime.
  2. Verify macro security: In Excel, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and ensure Enable all macros (or at least Disable all macros with notification) is selected. Disable macros will prevent any Sub from running.
  3. Check procedure scope: In the Procedure window (top-left of the code window), ensure the callee is listed as Public Sub (or just Sub) and not Private unless called from the same module.
  4. Confirm module location: Standard modules (under Modules) can call each other. Procedures in worksheet or workbook objects (e.g., ThisWorkbook, Sheet1) cannot be called directly from outside their object unless you prefix with the object name (e.g., Sheet1.MyProcedure).
  5. Test the callee alone: Run CalledSub directly using Alt + F8. If it fails to run, the issue is with the callee—not the call.
  6. Check for missing references: If the callee uses objects from external libraries (e.g., ADODB.Connection), ensure the reference is enabled via Tools > References in the VBA editor.

Frequently Asked Questions

Can I call a Sub from a different workbook?

Yes, but only if the other workbook is open. Use Application.Run "OtherWorkbook.xlsm!CalledSub". Include the full filename with extension, and include the module or sheet name if needed (e.g., "[OtherWorkbook.xlsm]Module1.CalledSub").

What’s the difference between Call CalledSub and CalledSub?

Both work. Using CalledSub is cleaner and more common. Call requires parentheses around arguments: Call CalledSub(arg1, arg2), whereas omitting Call allows optional parentheses: CalledSub arg1, arg2.

Can I call a Function instead of a Sub?

Yes. Functions can be called as statements (ignoring the return value) or assigned to a variable. Example: Dim result As Variant: result = MyFunction() or just MyFunction.

Why do I get a “Compile error: Expected function or variable”?

This usually means you wrote something like MySub = MyFunction instead of MyFunction. Ensure you’re not assigning the result unless you’re in an assignment context.

Can I pass a range or sheet object to another Sub?

Absolutely. Example:
Sub CallerSub()
    Call ProcessRange(ActiveSheet.Range("A1:B10"))
End Sub

Sub ProcessRange(rng As Range)
    rng.Interior.Color = RGB(255, 255, 0)
End Sub
Use appropriate object types (Range, Worksheet, Workbook) in parameter declarations.

Do procedures need to be in the same module?

No. Procedures in any standard module within the same VBA project can call each other. Only procedures in worksheet or workbook code sheets need to be qualified by object name when called externally.