ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to create a simple VBA Custom Function (https://www.excelbanter.com/excel-programming/362028-how-create-simple-vba-custom-function.html)

Edmund

How to create a simple VBA Custom Function
 
Through Insert | Name | Define, I can create a name (for example €śMyRatio€ť)
to hold the value 2.53. In VBA, how can I create a function to hold this
value?

I know nothing about creating Custom VBA Function and is trying to learn
from this simple example.

Lets give the function the name €śMyRatio€ť and I need it to hold any value
with 2 decimals.

Its ok to hardcode the value within the function procedure as I will edit
the value in VBA whenver the rate changes.

Any help is appreciated. Thanks a lot

--
Edmund
(Using Excel XP)

C01d[_2_]

How to create a simple VBA Custom Function
 

In your visual basic editor, right click on your project in the project
pane and select Insert - Module.

Write your function code in this new module.


--
C01d
------------------------------------------------------------------------
C01d's Profile: http://www.excelforum.com/member.php...o&userid=34422
View this thread: http://www.excelforum.com/showthread...hreadid=544145


tmingfai

How to create a simple VBA Custom Function
 

What is the difference if I insert my Function in a Module, class Module
and just a spreadsheet (e.g. Sheet1)


--
tmingfai
------------------------------------------------------------------------
tmingfai's Profile: http://www.excelforum.com/member.php...o&userid=34221
View this thread: http://www.excelforum.com/showthread...hreadid=544145


Cush

How to create a simple VBA Custom Function
 
tmingfai,

You can not define a Function in a cell or range of a spreadsheet. I think
you can define it in a Class Module, but I've never done that.

In a nutshell, the difference between a Macro and a Function is that macros
perform actions while Functions return a value. Functions don't *do*
anything.


"tmingfai" wrote:


What is the difference if I insert my Function in a Module, class Module
and just a spreadsheet (e.g. Sheet1)


--
tmingfai
------------------------------------------------------------------------
tmingfai's Profile: http://www.excelforum.com/member.php...o&userid=34221
View this thread: http://www.excelforum.com/showthread...hreadid=544145



Zone

How to create a simple VBA Custom Function
 
If you're intending to call function macros from a spreadsheet, you
should put them in a standard module.


Chip Pearson

How to create a simple VBA Custom Function
 
:I think
you can define it in a Class Module, but I've never done that.


You can't do that.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"cush" wrote in message
...
tmingfai,

You can not define a Function in a cell or range of a
spreadsheet. I think
you can define it in a Class Module, but I've never done that.

In a nutshell, the difference between a Macro and a Function is
that macros
perform actions while Functions return a value. Functions
don't *do*
anything.


"tmingfai" wrote:


What is the difference if I insert my Function in a Module,
class Module
and just a spreadsheet (e.g. Sheet1)


--
tmingfai
------------------------------------------------------------------------
tmingfai's Profile:
http://www.excelforum.com/member.php...o&userid=34221
View this thread:
http://www.excelforum.com/showthread...hreadid=544145






All times are GMT +1. The time now is 04:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com