internet.com
You are in the: Small Business Computing Channelarrow
Small Business Technology
» ECommerce-Guide | Small Business Computing | Webopedia | WinPlanet

WinPlanet Software Downloads and Reviews for Small Businesses
Search
Power Search | Tips
-
Navigate WinPlanet
WinPlanet Home Page

Software
Download Index
In-Depth Reviews
Tips & Tutorials
Updates
News

Software Categories
Browsers
Chat / Conferencing
Desktop Utilities
Development
Internet Apps
Multimedia
OS Service Packs
Productivity Tools

Software Glossary

WinPlanet Newsletter

internet.commerce
Partners & Affiliates













Small Business Computing
Small Business Computing
Ecommerce Guide
Webopedia
WinPlanet

WinPlanet / Reviews

Download of the day
Adobe Flash Player

Most Popular Software Downloads
Windows Vista Service Pack 2 (Vista SP2)
Mozilla Firefox 3
QuickTime for Windows
Adobe Flash Player
Windows 7
Norton Internet Security 2010
Internet Explorer 8
CCleaner (Crap Cleaner)
Winamp
Skype

Most Popular Software Articles
Windows Vista Tips: Home Networking Setup Tutorial
10 Must-Have Apps: The Free Windows Networking Toolkit
How to Make Your Internet Connection Faster, Better


Software Reviews

Exploring Office 2007: Creating Custom Functions in Excel 2007
Rolling Your Own Excel Functions
Helen Bradley

» Making Your Own Excel Functions

Often when you're working with Excel you will use a calculation that is not available as a built-in Excel function. If you make this calculation repeatedly, you can save having to write the calculation each time you use it and instead create a custom Excel function to do the work. Excel custom functions can also be created as Excel add-ins so that they are available for use in all workbooks.

To create a function, open a new Excel workbook and create a small worksheet as shown in the image to the right:

I'll show you how to create a custom function to calculate the selling price of an item using the following formula:

selling price - cost price * (1+markup percentage)

To make this calculation in cell D4 of the example worksheet (given the markup percentage is 50%) you would write this formula and copy it down the column:

=C4*(1+50%)

If you want to make this calculation repeatedly or have someone else do it, you can create a function that can be used in the same was as any other Excel function.

To do this, first display the Developer tab if it isn't yet visible by clicking the Office button, choosing Excel Options > Popular, and enabling the Show Developer tab in the Ribbon checkbox. Click OK.

Next, click the Developer tab on the Ribbon and click the Visual Basic icon to open the Visual Basic window. Locate VBA Project for the workbook you are working on. In our case it's VBA project (Book1). Select Insert > Module to add a code, which is where you type your VBA code.

This is the code for our function:

Function SellPrice(CostPrice, Percent_markup)
	SellPrice = CostPrice * (1 + Percent_markup)
End Function

The function is called sellprice and this is also the name that you use to refer to it when you write your formula in the worksheet. The function takes two values, one for cost price and one for percentage markup, and it uses these to make the calculation of the selling price.

If you're familiar with using Visual Basic, a lot of this detail will already be familiar to you. If not, there is one thing to be aware of when writing functions, which is that you must always assign the function name a value in the function code itself so you have a return value. In this case the function name is sellprice so you need at least one line that commences: "sellprice =" or the function won't work.

Return to the workbook and try the function by typing this formula into cell D4:

=sellprice(C4,50%)

You should see the result 34.5 which represents a selling price that is the original cost price of 23 marked up by 50%.

» Making Your Functions Accessible

If you were to try this formula in another workbook it wouldn't work as written because the module containing the function code wouldn't be in that workbook.

To use it you need to prefix the function name with the workbook name — a process that is undesirably complex and cumbersome but which can be avoided by making the workbook an Excel add-in, which we'll do shortly.

» More Advanced Calculations

In the meantime let's see a more complex function at work. Consider the situation where, if an item's cost price is less than ten dollars we add an additional one dollar to the selling price after the markup has been calculated and, if the item's cost price is ten dollars or more, then we add two dollars to the selling price after the markup has been calculated.

Here's the code for this particular function:

Function SellPrice(CostPrice, Percent_markup) as Currency
	SellPrice = CostPrice * (1 + Percent_markup)
	if CostPrice < 10 then 
		SellPrice = SellPrice + 1
	else
		SellPrice = SellPrice +2
	end if
End Function

This replacement function can be accessed in Excel in the same way as the earlier version but this time a more complex calculation is taking place behind the scenes. In addition, because this is Visual Basic code we can hide it from our user.

As a result, we could instruct someone how to write the formula to calculate the selling price of an item by telling them to type =sellingprice(item, percent markup) but we don't need to tell them how the actual calculation is made.

| Next Page »

Contents:
1. Rolling Your Own Excel Functions
2. Workbook Add-ins and More Excel Custom Functions




internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs