# Creating Excel worksheet functions

**URL:** <https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896>\
**Category:** Factual Questions\
**Created:** [February 25, 2005, 4:37pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896 "2005-02-25T16:37:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Happy\_Fun\_Ball](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/happy_fun_ball/32/17664_2.png) [@Happy\_Fun\_Ball](https://boards.straightdope.com/u/Happy_Fun_Ball)\
**Post date:** [February 25, 2005, 4:37pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/1 "2005-02-25T16:37:55Z")

</div>

How can I create a new worksheet function? I swear I did this once upon a time but I cannot figure out how to do it now.

Simple example: Say I want to create a function Cube(x), where x is either a number or a cell refernce and the result would be the cube. How can I do this?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![audiobottle](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@audiobottle](https://boards.straightdope.com/u/audiobottle)\
**Post date:** [February 25, 2005, 4:41pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/2 "2005-02-25T16:41:01Z")

</div>

Type in the ‘=’ or hit the fx button after clicking on the cell. Then enter in the function.

---

<div class="post-metadata">

**Author:** ![Happy\_Fun\_Ball](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/happy_fun_ball/32/17664_2.png) [@Happy\_Fun\_Ball](https://boards.straightdope.com/u/Happy_Fun_Ball)\
**Post date:** [February 25, 2005, 5:02pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/3 "2005-02-25T17:02:50Z")

</div>

> [@audiobottle](#):
>
> Type in the ‘=’ or hit the fx button after clicking on the cell. Then enter in the function.

I don’t think I did a very good job of asking the question. The function I want is a 6th order polynomial that I use in a lot of different places. Now instead of typing

=6.034e-8_x^5+4.3257e-6_x^4…

where x is typically a cell reference into every single cell I wan the formula, I would like to define a function:

[begin pseudo matlab code]

Function output = Poly(x)

output = =6.034e-8_x^5+4.3257e-6_x^4…

[end pseudo matlab code]

such that all I have to type in a cell is

=Poly(A2)

and it gives the right answer. I swear I have defined functions before in excel before I just cannot remeber how or find anything in the help files.

---

<div class="post-metadata">

**Author:** ![Balthisar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/balthisar/32/2825_2.png) [@Balthisar](https://boards.straightdope.com/u/Balthisar)\
**Post date:** [February 25, 2005, 5:42pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/4 "2005-02-25T17:42:54Z")

</div>

The quickest way to do it when I need to make a function is record a bogus Macro, open the visual basic editor, erase the macro function, and put your own function there. This way you’ll be assured that your function is in the right place.

---

<div class="post-metadata">

**Author:** ![Boldface\_Type](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@Boldface\_Type](https://boards.straightdope.com/u/Boldface_Type)\
**Post date:** [February 25, 2005, 5:59pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/5 "2005-02-25T17:59:04Z")

</div>

> [@Balthisar](#):
>
> The quickest way to do it when I need to make a function is record a bogus Macro, open the visual basic editor, erase the macro function, and put your own function there. This way you’ll be assured that your function is in the right place.

To expand this a bit:

In the VBA editor (ALT+F11), create your function. The syntax is basically:

Function name (parameters) as type  
name=some formula or other  
End Function

You can then directly access this function in your worksheet cells as:

=name()

So, you could create the wonderful function below:

Function four (y as Double) As Double  
four=4\*y  
End Function

Then, when you type =four(3) in the worksheet of which the macro is a part, you’ll get the number 12 in the cell.

You can refer to macros that are not present in the current workbook, and you can make the function an add in, if you wish.

---

<div class="post-metadata">

**Author:** ![audiobottle](https://avatars.discourse-cdn.com/v4/letter/a/bc8723/32.png) [@audiobottle](https://boards.straightdope.com/u/audiobottle)\
**Post date:** [February 25, 2005, 6:01pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/6 "2005-02-25T18:01:06Z")

</div>

Here’s a link to a Microsoft help page that might further help:

[link](http://office.microsoft.com/en-us/assistance/HA011117011033.aspx)

---

<div class="post-metadata">

**Author:** ![Happy\_Fun\_Ball](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/happy_fun_ball/32/17664_2.png) [@Happy\_Fun\_Ball](https://boards.straightdope.com/u/Happy_Fun_Ball)\
**Post date:** [February 25, 2005, 6:03pm UTC](https://boards.straightdope.com/t/creating-excel-worksheet-functions/291896/7 "2005-02-25T18:03:56Z")

</div>

Thanks all. I see.

I think the last time I did this was before VBA was integrated into Excel (am I dating myself?). Back then, it was much simpler as they just had a drop down menu item “create function” or something similar.
