Vba function problem

zaneta0709

New Member
Joined
Jun 10, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I don't know what i did wrong but when I'm trying to use those two Functions they are not running.

Here is my exercise :

2.JPG




And this is my vba function :



1PNG.JPG
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Welcome to the MrExcel board!

And this is my vba function :
It would help in future if you post your actual code rather than an image of it so that we can copy for testing. My signature block below has more on that.

As far as I can see, your issues are ..
antoine: Your function has t multiplied by C when they should be added
medication: e is the constant 2.718... not a variable input. In vba use the Exp() function for that.

So, try these

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

Function medication(C0 As Double, k As Double, t As Double) As Double
  medication = C0 * Exp(-(k * t))
End Function

Checks

zaneta0709.xlsm
ABCDE
1antoineABCt
2416.58453928.080971582.271239.72650
3
4medicationC0kt
527.067056652000.54
Sheet1
Cell Formulas
RangeFormula
A2A2=antoine(B2,C2,D2,E2)
A5A5=medication(B5,C5,D5)
 
Upvote 0
Welcome to the forum. :)

What exactly do you mean by "not running"? What is happening specifically?
 
Upvote 0
Also:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Vba function problem
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Welcome to the MrExcel board!


It would help in future if you post your actual code rather than an image of it so that we can copy for testing. My signature block below has more on that.

As far as I can see, your issues are ..
antoine: Your function has t multiplied by C when they should be added
medication: e is the constant 2.718... not a variable input. In vba use the Exp() function for that.

So, try these

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

Function medication(C0 As Double, k As Double, t As Double) As Double
  medication = C0 * Exp(-(k * t))
End Function

Checks

zaneta0709.xlsm
ABCDE
1antoineABCt
2416.58453928.080971582.271239.72650
3
4medicationC0kt
527.067056652000.54
Sheet1
Cell Formulas
RangeFormula
A2A2=antoine(B2,C2,D2,E2)
A5A5=medication(B5,C5,D5)
Thank you so much that solved my problem :)
 
Upvote 0
Thank you so much that solved my problem :)
Actually, since A, B & C in antoine are also constants, probably best if you include them in the function directly.
Edit: Posting too fast & missed the instruction about including those constants as arguments. I assume they are different constant values in different circumstances. :oops:

And a very minor point - you have an extra set of parentheses in the medication function that is not needed.

So slight refinements:

VBA Code:
Function antoine(t As Double) As Double
  antoine = 10 ^ (8.08097 - 1582.271 / (t + 239.726))
End Function

Function medication(C0 As Double, k As Double, t As Double) As Double
  medication = C0 * Exp(-k * t)
End Function

zaneta0709.xlsm
ABCD
1antoinet
2416.584539250
3
4medicationC0kt
527.067056652000.54
Sheet1
Cell Formulas
RangeFormula
A2A2=antoine(B2)
A5A5=medication(B5,C5,D5)
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,853
Members
449,471
Latest member
lachbee

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