New Function VBA / Beginner

Cocotte

New Member
Joined
Mar 20, 2018
Messages
2
I need to create a VBA Function in order to calculate the Antoine Formula.
P = 10^(A-(B/T+C))
T= Degree Celsius P= mmHg
Example: http://ddbonline.ddbst.com/AntoineCalculation/AntoineCalculationCGI.exe?component=Methanol
I got to say the Celsius is making me totally confuse.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Function antoine( A as double, B as Double, C as Double, T as Double) aS Double
Dim T as ..........
antoine
= 10^(A-(B/T+C))
End Function</code>Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I don't understand the topic in your link but you don't want to redim values that you are using as parameters in your function and you do need a space between the as and the data type. Your parentheses didn't seem quite correct though.

Code:
Function antoine(A As Double, B As Double, C As Double, T As Double) As Double
antoine = 10 ^ (A - (B / (C + T)))
End Function


Excel 2010
ABCDE
18.080971582.27239.71002649.262
Sheet1
Cell Formulas
RangeFormula
E1=antoine(A1,B1,C1,D1)
 
Last edited:
Upvote 0
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=2]#2[/URL] 42729]I got to say the Celsius is making me totally confuse.
[/COLOR]
Is your problem that you have your temperatures in degrees Fahrenheit? If so, try this for your function...
Code:
[table="width: 500"]
[tr]
	[td]Function Antoine(A As Double, B As Double, C As Double, T As Double) As Double
  Antoine = 10 ^ (A - (B / (C + 5 * (T - 32) / 9)))
End Function[/td]
[/tr]
[/table]
Note: I applied the correction for your parentheses as Scott pointed out in Message #2 .
 
Last edited:
Upvote 0
Is your problem that you have your temperatures in degrees Fahrenheit? If so, try this for your function...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Function Antoine(A As Double, B As Double, C As Double, T As Double) As Double
  Antoine = 10 ^ (A - (B / (C + 5 * (T - 32) / 9)))
End Function[/TD]
[/TR]
</tbody>[/TABLE]
Note: I applied the correction for your parentheses as Scott pointed out in Message #2 .

My confusion with "T" is that, how excel know this is Celsius? Don't I need to define the value differently?

Thanks for the parenthesis, I didn't realized right away.
 
Upvote 0
My confusion with "T" is that, how excel know this is Celsius? Don't I need to define the value differently?
Excel doesn't know anything... all it sees is that you are passing in a number for the T argument.... it is the formula that "knows", well, rather "assumes", that the number is Celcius. It is incumbent on you (or your workbook's user) to know that the number inputted for T is supposed to be Celsius and to make sure that is the only kind of temperature that is specified. There would be know way for the formula to determine if the number is Celsius or Fahrenheit on its own (that is because the possible ranges for each overlap each other... if you pass in 40, that would be a legitimate value in either temperature scale). If you know you will always be working in Celsius, then use the formula Scot gave you; but if instead you know your values will always be Fahrenheit, then use the code I gave you instead (it converts Fahrenheit to Celsius directly within the code).
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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