How to fix this true value in my Public Function?

kingman29

Board Regular
Joined
Jun 22, 2021
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Hello
First I want to thank @JackDanIce for gave me an excellent solution
Second I marge his function (his solution) into my function.
So
When I tried to calculate The "Percentage_CP" must be this value =
0.001256831​
Witch mean the Result in Cell "E6" will = 588 404.74630183
But it show me this =
0.001255254​
So this this Result = 587 666.149010485 is Fault not true
so How to fix it ? please
thank you veryMatch

*************************************
boutton.xlsm
ABCDE
1Cost1-411 269 098.48
2Pourcentage0.14%
3
4Devesement Pourcentage0.13%
5
6Deversement 587 666.15
Feuil1
Cell Formulas
RangeFormula
E6E6=deversement(B1,B2,B4)


****************************

The function in the Module is
VBA Code:
Public Function deversement(Charge_Centre_Principal, Centre1 As String, Percentage_CP As Double) As Double
Dim y As Double
    For y = 2 To 40
        deversement = (-Charge_Centre_Principal * Centre1) * (1 + TauxCP + Application.Power(TauxCP, y))
    Next y
End Function
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
There's a missing variable, so the used one will initialize to 0 (zero). Try this:

VBA Code:
Public Function deversement(Charge_Centre_Principal, Centre1 As String, TauxCP As Double) As Double

Dim y As Double
    For y = 2 To 40
        deversement = (-Charge_Centre_Principal * Centre1) * (1 + TauxCP + Application.Power(TauxCP, y))
    Next y
End Function
 
Upvote 0
There's a missing variable, so the used one will initialize to 0 (zero). Try this:

VBA Code:
Public Function deversement(Charge_Centre_Principal, Centre1 As String, TauxCP As Double) As Double

Dim y As Double
    For y = 2 To 40
        deversement = (-Charge_Centre_Principal * Centre1) * (1 + TauxCP + Application.Power(TauxCP, y))
    Next y
End Function

The Result is =
588 403.82​

It's wrong result
 
Upvote 0
You are not declaring the Charg_Centre_Principal variable explicit as a Double type, so it implicitly would be a Variant type holding any type.
Furthermore, you're declaring the Centre1 as a String type variable, despite it's used for calculations. Best would be to declare it as a Double type.
Don't know if this resolves your problem. I do have some VBA knowledge but (sorry to say) I'm not a math geek.
Hopefully some other forum member is able to help you with that part.

Rich (BB code):
Public Function deversement(ByVal Charge_Centre_Principal as Double, ByVal Centre1 As Double, TauxCP As Double) As Double

Dim y As Double
    For y = 2 To 40
        deversement = (-Charge_Centre_Principal * Centre1) * (1 + TauxCP + Application.Power(TauxCP, y))
    Next y
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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