Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Writing a user-defined worksheet function

On an MS site, it referred to a document called "Writing a user-defined
worksheet function". I am a long-time Excel user, but don't have VB
experience. I want to create my own finctions that will calculate various
chemical parameters from user input arguements. Can anyone point me int he
right direction?

My needs are pretty simple; I'd like to do things like create a function to
calculate the vapor pressure of water at a specified temperature, so I can
just type "=Pw(25)" to get the answer for 25 °C

Pw=760*EXP(11.8571-(3840.7/(T+273.15))-(216961/(T+273.15)^2))
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Writing a user-defined worksheet function

Try this:

Hit Alt-F11
Insert/Module

Paste the following into the code pane that appears. Then, close the VBA
editor and enter =PW(25) in a cell. I get 23.75898 using the formula you
posted.
For more info on VBA see
http://www.mvps.org/dmcritchie/excel/excel.htm
and scroll down to Excel lessons and tutorials (a little over halfway down
the page).


Function PW(T As Double) As Double
PW = 760 * Exp(11.8571 - (3840.7 / (T + 273.15)) - (216961 / (T + 273.15) ^
2))
End Function


"Russell Seguin" wrote:

On an MS site, it referred to a document called "Writing a user-defined
worksheet function". I am a long-time Excel user, but don't have VB
experience. I want to create my own finctions that will calculate various
chemical parameters from user input arguements. Can anyone point me int he
right direction?

My needs are pretty simple; I'd like to do things like create a function to
calculate the vapor pressure of water at a specified temperature, so I can
just type "=Pw(25)" to get the answer for 25 °C

Pw=760*EXP(11.8571-(3840.7/(T+273.15))-(216961/(T+273.15)^2))

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Writing a user-defined worksheet function

Put this in a standard module.

Public Function pw(TempC As Double) As Double
pw = 760 * Exp(11.8571 - (3840.7 / (TempC + 273.15)) - (216961 /
(TempC + 273.15) ^ 2))
End Function

Hth,
Merjet


  #4   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Writing a user-defined worksheet function

Try this:

Hit Alt-F11
Insert/Module

Paste the following into the code pane that appears. Then, close the VBA
editor and enter =PW(25) in a cell. I get 23.75898 using the formula you
posted.
For more info on VBA see
http://www.mvps.org/dmcritchie/excel/excel.htm
and scroll down to Excel lessons and tutorials (a little over halfway down
the page).


Function PW(T As Double) As Double
PW = 760 * Exp(11.8571 - (3840.7 / (T + 273.15)) - (216961 / (T + 273.15) ^
2))
End Function


"Russell Seguin" wrote:

On an MS site, it referred to a document called "Writing a user-defined
worksheet function". I am a long-time Excel user, but don't have VB
experience. I want to create my own finctions that will calculate various
chemical parameters from user input arguements. Can anyone point me int he
right direction?

My needs are pretty simple; I'd like to do things like create a function to
calculate the vapor pressure of water at a specified temperature, so I can
just type "=Pw(25)" to get the answer for 25 °C

Pw=760*EXP(11.8571-(3840.7/(T+273.15))-(216961/(T+273.15)^2))

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Writing a user-defined worksheet function

Thanks! It was easier than I thought; I bet I could even figure out how to
do functions with 2 arguements/variables...

Russell


"JMB" wrote:

Try this:

Hit Alt-F11
Insert/Module

Paste the following into the code pane that appears. Then, close the VBA
editor and enter =PW(25) in a cell. I get 23.75898 using the formula you
posted.
For more info on VBA see
http://www.mvps.org/dmcritchie/excel/excel.htm
and scroll down to Excel lessons and tutorials (a little over halfway down
the page).


Function PW(T As Double) As Double
PW = 760 * Exp(11.8571 - (3840.7 / (T + 273.15)) - (216961 / (T + 273.15) ^
2))
End Function


"Russell Seguin" wrote:

On an MS site, it referred to a document called "Writing a user-defined
worksheet function". I am a long-time Excel user, but don't have VB
experience. I want to create my own finctions that will calculate various
chemical parameters from user input arguements. Can anyone point me int he
right direction?

My needs are pretty simple; I'd like to do things like create a function to
calculate the vapor pressure of water at a specified temperature, so I can
just type "=Pw(25)" to get the answer for 25 °C

Pw=760*EXP(11.8571-(3840.7/(T+273.15))-(216961/(T+273.15)^2))



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Writing a user-defined worksheet function

What's the difference between a Function and a Public Function?

Thanks!

Russell

"merjet" wrote:

Put this in a standard module.

Public Function pw(TempC As Double) As Double
pw = 760 * Exp(11.8571 - (3840.7 / (TempC + 273.15)) - (216961 /
(TempC + 273.15) ^ 2))
End Function

Hth,
Merjet



  #7   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Writing a user-defined worksheet function

Public functions can be used by procedures in other modules while private
functions cannot be accessed by procedures in other modules.

If not specified, functions are public by default - so the answer to your
question is there is no difference.

Check VBA help for "Function Statement"

"Russell Seguin" wrote:

What's the difference between a Function and a Public Function?

Thanks!

Russell

"merjet" wrote:

Put this in a standard module.

Public Function pw(TempC As Double) As Double
pw = 760 * Exp(11.8571 - (3840.7 / (TempC + 273.15)) - (216961 /
(TempC + 273.15) ^ 2))
End Function

Hth,
Merjet



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
User defined function returns imprecise value when used in worksheet JohnM[_3_] Excel Discussion (Misc queries) 3 December 1st 09 12:52 PM
User Defined Function use any worksheet Babylynn Excel Discussion (Misc queries) 2 April 1st 09 06:23 PM
Using dcount function within user-defined worksheet function pongthai Excel Programming 3 January 15th 07 09:55 AM
Error messages from user defined Excel worksheet function Tom Ogilvy Excel Programming 3 March 18th 06 04:30 PM
Automatic calculation of user-defined worksheet function Bart Deschoolmeester Excel Programming 2 October 8th 03 04:37 PM


All times are GMT +1. The time now is 02:15 PM.

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

About Us

"It's about Microsoft Excel"