Chapter 17 Excel Tutorials Script

advertisement
(Ch. 17) 1
Chapter 17 Excel Tutorial Script























Welcome to Chapter 17, Building Custom Functions within VBA
After completing this tutorial, you should be able to create custom functions that can be
used within Excel. This process takes place within Visual Basic for Applications (VBA).
This is the application that works behind the scenes of Word, Excel, Access, and other
Microsoft Office programs. The advantage of creating a function that is in VBA is that
the user does not have to worry about maintaining a formula within a cell. The user will
only have to create this function once, and can use it repeatedly. This tutorial will show
you how to create a Taguchi Quality Loss Function within VBA, and then use it within
Excel.
To begin open a blank Excel document
Go to the “Developer” ribbon tab. If you do not have the developer ribbon showing, go
to File, Options, Customize Ribbon tab, and select Developer under the main tabs list.
Once we have the developer ribbon, go to it.
First, we will select Macro Security, and make sure that “Enable all macros” is selected.
Next click the Visual Basic button to open the VBA window.
Once in the VBA window go to the toolbar select Insert, and select Module
This will open a new module for us to create our function. To tell Visual Basic you
would like to create a function, type Function and a space.
After the space we will name our function “Taguchi”
Within the parentheses we will create the names of the parameters used within the
function. Type “TotalQuality, ToleranceAllowed, x, T).” Then hit enter.
Now tab in one time to define the function tied to the function we created above named
Taguchi.
We will type in “Taguchi = (TotalQuality / (ToleranceAllowed ^ 2)) * (x – T) ^ 2”
Our final entry in VBA should look like the one that appears on the screen
Go to file, and click on save to save the function. You will have to change your save as
type: from Excel Workbook to Excel Macro-Enabled Workbook.
Now close out of Visual Basic
Go back into Excel, and enter the data from Self-Study Problem #2 on page 779 as shown
on the screen
Now in cell B5, we are able to use our new Taguchi function. To do this, select the
function key
Within the new window choose User Defined from the Select a Category drop-down list,
select Taguchi and select OK
The function arguments window for the Taguchi function will now appear. Using the
select button, select the relevant data as shown
Finally select OK. Your answer should be 8.2944.
You have successfully built custom functions within VBA
Having completed this tutorial, you should now be able to create custom functions that
can be used within Excel. This process takes place within Visual Basic for Applications
(VBA). This is the application that works behind the scenes of Word, Excel, Access, and
other Microsoft Office programs. The advantage of creating a function that is in VBA is
(Ch. 17) 2

that the user doesn’t have to worry about maintaining a formula within a cell. The user
will only have to create this function once, and can use it repeatedly. This tutorial
showed you how to create a Taguchi Quality Loss Function within VBA, and then use it
within Excel.
You have successfully completed Chapter 17, Building Custom Functions within VBA,
of the Excel Tutorial Series
Download