VBA have a sub run another sub

Stephan Daudt picture Stephan Daudt · Jan 29, 2013 · Viewed 45.7k times · Source

how to run a sub stored in another worksheet's module?

worksheet1

sub endDay()
    'something here
end sub

worksheet2

sub reCalc()
    'something here
end sub

I want recalc to be able to run on its own but I want to be able to press the button for "endDay", have it do its thing, and then preform "recalc" at the end instead of pressing one and then go to sheet2 to press the other.

Can someone give me a sample so I can have an idea where to begin?

Answer

Peter Albert picture Peter Albert · Jan 29, 2013

Take a look at the code names for the worksheets - you can see them in the tree view in the Visual Basic Editor. Usually they are named Sheet1, Sheet2, etc. (independent of the actual worksheet names, which are shown in brackets). Use this name in your code )instead of Worksheets("Sheet1")and you'll also get an autocomplete list - with your sub!

Thus, this will do the job:

Sheet1.reCalc