Custom Functions not available in spreadsheet

jacques330ci

New Member
Joined
Oct 6, 2016
Messages
6
Hello all,

I am experience a problem accessing the custom functions I have created via VBA code in Excel. This occurs in both 2007 and Office 365 versions:

I am able to write the code (see below) for the function named CalculateArea(), compile it successfully with no errors, and it appears in the Declarations drop-down box of the VBA code editor. But when I switch over to the accompanying spreadsheet, I am unable to access the function (it does not appear in the shortcut list when I type "=CalculateArea" into a blank cell; nor does it appear in the Insert Function dialog box). There isn't even a category listed for 'Custom', 'User-Defined', etc. in the Insert Functions dialog box.

Both installations of Excel were made to include all features (everything set to 'Run from My Computer').

Can someone please advise me on what I am missing?

Public Function CalculateArea(Length As Double, Width As Double) As Double
Dim Area As Double

Area = Length * Width
CalculateArea = Area
End Function

Thank you in advance for any help you can provide me. BTW, this website's design is AWESOME!

jacques
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
jacques330ci,

Welcome to the MrExcel forum.

If I understand you correctly, how about something like this:


Excel 2007
ABCD
1275.7865
2
312.2322.55275.7865
4
Sheet1
Cell Formulas
RangeFormula
A1=CalculateArea(12.23,22.55)
C3=CalculateArea(A3,B3)






Code:
Public Function CalculateArea(Length As Double, Width As Double) As Double
Dim Area As Double
Area = Length * Width
CalculateArea = Area
End Function


How to install the User Defined Function:

1. Open up your workbook
2. Get into VB Editor (Press Alt+F11)
3. Insert a new module (Insert > Module)
4. Copy and Paste in your code (given above)
5. Get out of VBA (Press Alt+Q)
6. Save as a macro-enabled workbook

The function is installed and ready to use as shown in the example above.
 
Upvote 0
Hello hiker95,
Thanks for responding.
When I enter the same code and save the worksheet as macro-enabled, this is what displays in the cell:

#NAME?

My screenshot is a jpeg, and could help to see what's happening, but on my computer, not accessible via URL


jacques
 
Upvote 0
Don't see how this should make a difference, but the Excel 2007 is installed in a Virtual PC instance of Windows 7 OS for training purposes, and the Excel 2013 is installed on the Windows 7 host. I have Excel 2010 on another PC but I haven't tried that one.
 
Upvote 0
Hi jacques

Did you insert the code in a general module?
The udf code cannot be inserted in the worksheet module.

Remark: really (really) bad choice of variable names. All Length, Width and Area are names of object properties in vba. This is bad practice.
 
Upvote 0
Hello hiker95,
Thanks for responding.
When I enter the same code and save the worksheet as macro-enabled, this is what displays in the cell:

#NAME?

My screenshot is a jpeg, and could help to see what's happening, but on my computer, not accessible via URL


jacques

jacques330ci,

Can we see your actual workbook/worksheet(s)?

You can post your workbook/worksheets to the following free site (sensitive data changed), mark the workbook for sharing, and, provide us with a link to your workbook:

https://dropbox.com
 
Upvote 0
Hi PGC

Thank you! That was the issue. I was using a General module. Once I used the Class Module, it worked.

And thanks for the tip regarding the choice of variable names. This is actually a tutorial that I am doing and just using what they suggest, which excluded the Class Module requirement.

Much appreciated,
Jacques
 
Upvote 0
ok, thanks hiker95.

that's so cool. I wondered how you got the worksheet views in here.
You and PGC are doing great work and a much need service to the Excel user community.

Have a great weekend,
Jacques
 
Upvote 0
ok, thanks hiker95.

that's so cool. I wondered how you got the worksheet views in here.
You and PGC are doing great work and a much need service to the Excel user community.

Have a great weekend,
Jacques

jacques330ci,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top