calling a macro using if statement?

aspiringnerd

New Member
Joined
Apr 22, 2022
Messages
39
Office Version
  1. 365
Platform
  1. Windows
some weird stuff is happening when I combine a bunch of macros together but work fine if I run them seperately. Rather than calling them the traditional way, is it possible to use an if statement to trigger another code automatically?
VBA Code:
sub autotrigger()
if codeA = TRUE then
calls code B
else

endif


end sub

I've tried putting a delay in my code, but it doesnt work. I'm just trying to have a function execute once the first function completely executes.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Technically, you cannot without having separate calls or events that trigger subsequent code to execute. IF the last line in a procedure calls another procedure, that's as close as you can get. When the 2nd, 3rd... last procedure in the stack executes End Sub or End Function, control is given to the last in the stack. Rinse and repeat.

You could make the calls to functions that return values and make what happens next contingent upon the returned value if that helps, but methinks it's not what you're trying to do.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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