Save the result of VBA custom function

Sahraoui Khaled Ibn El-Walid 1 Reputation point
2021-10-25T14:47:10.353+00:00

Hello
I create a costum VBA function
Function puissance2(Taux_CPrincpal As Double) As Double
Dim x As Double
puissance2 = Taux_CPrincpal
For x = 2 To 40
puissance2 = (puissance2 + Application.Power(Taux_CPrincpal, x))
Next x
End Function

Function Deversement(La_Somme_Charge, Centre_Coûte_Aux As String, Le_Rapport_Activité As Range, N°_Colonne As Double, Taux_Centre_Princ As Double) As Double  
Deversement = (-La_Somme_Charge * Application.WorksheetFunction.VLookup(Centre_Coûte_Aux, Le_Rapport_Activité, N°_Colonne, 0)) * (1 + puissance2(Taux_Centre_Princ))  
If Deversement = "-0" Then  
Deversement = "0"  
End If  
End Function  

and it's gave me this result when I close and tr-open the File and it's start from the begining
143502-deversement-vba.png (Picture 02)

Its like the Excel Function :
=(-$I$22*RECHERCHEV(C23;'SDC Z04'!$C$15:$F$174;4;0))*(1-PUISSANCE('SDC Z04'!$F$25;1)-PUISSANCE('SDC Z04'!$F$25;2)-PUISSANCE('SDC Z04'!$F$25;3)-PUISSANCE('SDC Z04'!$F$25;4)-PUISSANCE('SDC Z04'!$F$25;5)-PUISSANCE('SDC Z04'!$F$25;6)-PUISSANCE('SDC Z04'!$F$25;7)-PUISSANCE('SDC Z04'!$F$25;8)-PUISSANCE('SDC Z04'!$F$25;9)-PUISSANCE('SDC Z04'!$F$25;10)-PUISSANCE('SDC Z04'!$F$25;11)-PUISSANCE('SDC Z04'!$F$25;12)-PUISSANCE('SDC Z04'!$F$25;13)-PUISSANCE('SDC Z04'!$F$25;14)-PUISSANCE('SDC Z04'!$F$25;15)-PUISSANCE('SDC Z04'!$F$25;16)-PUISSANCE('SDC Z04'!$F$25;17)-PUISSANCE('SDC Z04'!$F$25;18)-PUISSANCE('SDC Z04'!$F$25;19)-PUISSANCE('SDC Z04'!$F$25;20)-PUISSANCE('SDC Z04'!$F$25;2)-PUISSANCE('SDC Z04'!$F$25;21)-PUISSANCE('SDC Z04'!$F$25;22)-PUISSANCE('SDC Z04'!$F$25;23)-PUISSANCE('SDC Z04'!$F$25;24)-PUISSANCE('SDC Z04'!$F$25;25)-PUISSANCE('SDC Z04'!$F$25;26)-PUISSANCE('SDC Z04'!$F$25;27)-PUISSANCE('SDC Z04'!$F$25;28)-PUISSANCE('SDC Z04'!$F$25;29)-PUISSANCE('SDC Z04'!$F$25;30)-PUISSANCE('SDC Z04'!$F$25;31)-PUISSANCE('SDC Z04'!$F$25;32)-PUISSANCE('SDC Z04'!$F$25;33)-PUISSANCE('SDC Z04'!$F$25;34)-PUISSANCE('SDC Z04'!$F$25;35)-PUISSANCE('SDC Z04'!$F$25;36)-PUISSANCE('SDC Z04'!$F$25;37)-PUISSANCE('SDC Z04'!$F$25;38)-PUISSANCE('SDC Z04'!$F$25;39)-PUISSANCE('SDC Z04'!$F$25;40))

and this function gave me this result even After re-open the File, (wich mean the Results after re-open the Excel File steel correct without recalculate
143532-deversement-vba.png


I want when the VBA Code when I close the Excel File, gave me the same result when I closed the Excel File, because in my case, it gave an error, and stop calculating

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.