Microsoft Office Tutorials and References
In Depth Information
Create Your Own Functions
Figure 18-10:
making a bad
The error message can be customized. For example if someone enters the
wrong number, the displayed error message can say “ Noodlehead — learn
how to count!” Just don’t let the boss see that.
Create Your Own Functions
Despite all the functions provided by Excel, you may need one that you just
don’t see offered. Excel lets you create your own functions by using VBA
programming code; your functions show up in the Insert Function dialog box.
Okay, I know what you’re thinking: Me, write VBA code? No way! It’s true —
this is not for everyone. But nonetheless, here is a short and sweet example.
If you can conquer this, then you may want to find out more about
programming VBA. Who knows, maybe one day you’ll be churning out sophisticated
functions of your own! Make sure you are working in a macro-enabled
workbook (one of the Excel file types).
Follow along to create custom functions:
1. Press Alt + F11.
This gets you to the Visual Basic Editor, where VBA is written.
You can also click the Visual Basic button on the Developer tab on
the Ribbon. The Developer tab is visible only if checked on the
Customize Ribbon tab in Excel Options.
2. Choose Insert Module in the editor.
You have an empty code module sitting in front of you. Now it’s time to
create your very own function!
3. All you have to do is type this programming code, shown in Figure 18-11:
Public Function Add(number1 As Double, number2 As
Add = number1 + number2
End Function
4. Save the function.
Search JabSto ::

Custom Search