Executing Function procedures by calling from a Sub procedure
In this last recipe, we will be calling the Function procedure from a Sub procedure. Once again, unless we call a Function procedure directly in Excel, the only other way to execute it is to call it from a Sub procedure.
Getting ready
Press Alt + F11 to activate the VBA Editor.
How to do it…
Follow these steps to create a Sub procedure to call the Exponent Function procedure:
- Under the last procedure in the code window, type the following code:
Sub CallSample() Â Â Â Â Result = Exponent(5, 2) Â Â Â Â MsgBox Result End Sub
- Save the file, and then press F5 to run the procedure.
How it works…
Function procedures cannot be executed like standard procedures. You cannot even execute it by running it as a macro. The only way to run a function is to use it in the Excel spreadsheet like a built-in function, or to call it from another procedure. That...