call a macro, then go back to the original sub

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I have multiple Subs for users to choose from, each one is specific to their territory.

I also have one Sub that runs an InputBox, entered data is used later in the specific territory Sub.

VBA Code:
Option Explicit
Sub Quarter()
Dim strQtr As String
strQtr = InputBox("enter Quarter here (1,2,3,4)")

End Sub

In each of my other Subs there is a line to Call Quarter, once Quarter runs, how do I get the marco to return back to where it left off, the line after Call Quarter?

Thank you,
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You don't need to tell it to do anything.
If you have macro B called from macro A, it will continue on with macro A after finishing macro B automatically (unless you have something in macro B to stop the whole thing, like exiting Excel).
 
Upvote 0
If you have this procedure in the standard module and you want to return value from input box to some other procedure
you can do it following this example.
First you need to have variable declared as public in the standard module.
This variable need to be initialized to be active,
so first go with code to module with this variable to activate it.
Example...
Put this in the standard module...
VBA Code:
Option Explicit

Public strQtr As String 'declare variable as public

Sub InitializeVariables()
    'initialize empty sub to collect public variable
End Sub

Sub Quarter()

    strQtr = InputBox("enter Quarter here (1,2,3,4)")

End Sub
And this in the UserForm module...
VBA Code:
Private Sub CommandButton1_Click()
        
    Call Quarter
    MsgBox strQtr
        
End Sub

Private Sub UserForm_Initialize()
    
    Call InitializeVariables
    
End Sub
 
Upvote 0
You don't need to tell it to do anything.
If you have macro B called from macro A, it will continue on with macro A after finishing macro B automatically (unless you have something in macro B to stop the whole thing, like exiting Excel).
I'm so embarrassed, I knew that. I did have a birthday on Sunday, perhaps this is a sign of old age.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top