Solved How to combine 2 or 3 VBA programs into 1

September 6, 2018 at 08:25:43
Specs: Windows 10, I3

I have two VBA programs for the same Excel spreadsheet and would like to combine them into one VBA program but I just can't seem to get that to work. I have found an article on Run / Trigger multiple macros by using a button with VBA code and using Sub MasterMacro()

Call Macro1
Call Macro2
Call Macro3
Call Macro4
End Sub
What do you think? The reason for doing this is to reduce having to run each macro one at a time.
What I have tried is to take the out the Sub do_it() on the second program and the End Sub out of the first program. I have included the ending and the beginning to show you the programs.
If anyone could assist/advice it sure would be appreciated.

MsgBox "Found a postivive result in " & cell.Address
End If


End Sub

Sub do_it()

See More: How to combine 2 or 3 VBA programs into 1

September 6, 2018 at 10:07:02
✔ Best Answer
What is wrong with using the "MasterMacro" technique to call the macros individually? If it works, it's a viable option.

Without seeing the actual macros it is impossible for us to tell you why simply removing the Sub and End Sub lines doesn't work, other than to say that that technique rarely works.

There is typically much more to a macro than just a bunch of individual instructions that get executed one at a time. There are relationships between variables, objects that get defined, etc. These things typically get "cleaned up" when an individual macro ends. When you try to combine macros, things begin to overlap and can cause havoc. IOW, the 2nd "macro" still know about everything that was set up by the 1st macro because the combined macro was compiled as a single unit.

How To Post Data or Code ---> Click Here Before Posting Data or VBA Code

message edited by DerbyDad03

Report •

September 7, 2018 at 06:55:41
Sorry about the code examples, I was just using a line as an example and not thinking of it as code - got it.

Thanks for your feedback it will help me.

Report •
Related Solutions

Ask Question