Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default 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)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default 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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a simple input box Marilyn Excel Discussion (Misc queries) 4 October 28th 08 09:08 AM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Create custom function andyiain Excel Discussion (Misc queries) 3 March 31st 06 04:33 PM
Create custom function and add to the Flamikey[_2_] Excel Programming 1 January 11th 04 01:31 AM
Trying to create a custom "clear worksheet" function (in a VBA module) Scott Lyon Excel Programming 1 July 29th 03 08:34 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"