Skip to Content
Advanced Modelling in Finance Using Excel and VBA
book

Advanced Modelling in Finance Using Excel and VBA

by Mary Jackson, Mike Staunton
June 2001
Intermediate to advanced
276 pages
8h 1m
English
Wiley
Content preview from Advanced Modelling in Finance Using Excel and VBA

Chapter 4. Writing VBA User-defined Functions

As well as automating spreadsheet operations, VBA code can be used to write functions which work in the same way as Excel's 'built-in' functions. Functions are particularly useful when they automate calculation tasks that are required repeatedly. Function calculations are carried out 'off sheet', allowing leaner and cleaner layouts to be devised, and functions are portable so that once programmed they can be copied to other workbooks.

Whereas a VBA subroutine usually performs one or more actions, a VBA function is a set of instructions that returns a single value (similar to the SUM function) or an array of values (like the LINEST function). User-defined functions combine real programming (complete with loops and conditional branching) together with Excel functions (such as NORMSDIST and MMULT).

Functions are simplest to write when they operate on single numerical inputs (scalar inputs) and when they return single cell values. This chapter starts by developing a simple sales commission function with one input and one output to illustrate the steps involved in writing and using functions. Functions with several scalar inputs are written in much the same way. As an illustration, a mathematically more challenging function based on the Black–Scholes option value formula is used. Function writing becomes more exacting when the inputs are arrays rather than single values. To illustrate some aspects of handling arrays, functions for the expected ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Hedge Fund Modelling and Analysis Using Excel and VBA

Hedge Fund Modelling and Analysis Using Excel and VBA

Paul Darbyshire, David Hampton

Publisher Resources

ISBN: 9780471499220Purchase book