10.2. Creating a Function

This section walks you through the process of creating a function.

10.2.1. Starting a Function Manually

The easiest way to start creating a function is to type into the VBA Code window the word Function, followed by the name you want to give to the function, and the necessary arguments in parentheses, and then press Enter. VBA automatically enters a blank line and an End Function statement for you and places the insertion point on the blank line ready for you to create the function. For example, if you type the following line and press Enter, the Visual Basic Editor displays what you see in Figure 10.1:

Function MyFunction(MaxTemp, MinTemp)
Figure 10.1. When you type a Function statement and press Enter, the Visual ...

Get Mastering VBA for Microsoft Office 2007, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.