Adding functions to a code module is very similar to Inserting Subroutines.
This page describes how you can insert an Excel User Defined Function so it can be used in a formula.

Display the Developer Tab

Select the File tab and choose the Options at the bottom.
Choose the Customise Ribbon tab and tick the Developer checkbox.

Press OK.

Display the Visual Basic Editor

Press the Visual Basic button (on the left hand side) to display the Visual Basic Editor.
Select (Insert > Module) to insert a new code module.

You can create a new function by using the (Insert > Procedure) dialog box, or ..

You can copy and paste a user defined function straight into the code window.

Any "Public" functions that have been saved in the VBA Project can be called from your Excel formulas.
Select (File > Save) to save these changes.
Switch back to Excel.
You can now access and use this function in exactly the same way you would use a built-in function.

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext