How to fix For - To Statement in my custom Function ?

kingman29

Board Regular
Joined
Jun 22, 2021
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Hello
Thank you for your Help and everytime I found my sollution with you
My situation today with my code Vba with My costum Function
Classeur1.xlsm
ABCD
3center 115,533%118,3891%100,0000%
Feuil1
Cell Formulas
RangeFormula
B3B3=+G3/$G$11
C3C3=+(POWER($B$3,0)+POWER($B$3,1)+POWER($B$3,2)+POWER($B$3,3)+POWER($B$3,4)+POWER($B$3,5)+POWER($B$3,6)+POWER($B$3,7)+POWER($B$3,8)+POWER($B$3,9)+POWER($B$3,10)+POWER($B$3,11)+POWER($B$3,12)+POWER($B$3,13)+POWER($B$3,14)+POWER($B$3,15))
D3D3=+puissance2(B3)


I need in my calculation that every time I add a power of my rate 15 Times
so, the Excel Formula is ;
Excel Formula:
=+(PUISSANCE($B$3;0)+PUISSANCE($B$3;1)+PUISSANCE($B$3;2)+PUISSANCE($B$3;3)+PUISSANCE($B$3;4)+PUISSANCE($B$3;5)+PUISSANCE($B$3;6)+PUISSANCE($B$3;7)+PUISSANCE($B$3;8)+PUISSANCE($B$3;9)+PUISSANCE($B$3;10)+PUISSANCE($B$3;11)+PUISSANCE($B$3;12)+PUISSANCE($B$3;13)+PUISSANCE($B$3;14)+PUISSANCE($B$3;15))

This code gave my this result =
118,3891%​

and VBA code gave me :
100,0000%​
with this Code VBA

VBA Code:
Public Function puissance2(Taux_CPrincpal As Double) As Double

On Error Resume Next
Dim x As Double
     puissance2 = Taux_CPrincpal
       For x = 1 To 15
     puissance2 = Application.Power(Taux_CPrincpal, 0) + Application.Power(Taux_CPrincpal, x)
    Next x
End Function

-----------

I know there is a mistake in my code VBA ,
So I need your help, and Will be very thankfull even without help
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
It looks like your code should be:

VBA Code:
Public Function puissance2(Taux_CPrincpal As Double) As Double

On Error Resume Next
Dim x As long
       For x = 0 To 15
     puissance2 = puissance2 + Application.Power(Taux_CPrincpal, x)
    Next x
End Function

or:
VBA Code:
Public Function puissance2(Taux_CPrincpal As Double) As Double
puissance2 = 1
On Error Resume Next
Dim x As long
       For x = 1 To 15
     puissance2 = puissance2 + Application.Power(Taux_CPrincpal, x)
    Next x
End Function
 
Upvote 0
Solution
Hi
Try
VBA Code:
Public Function puissance2(Taux_CPrincpal As Double) As Double

On Error Resume Next
Dim x As Double
     puissance2 = Taux_CPrincpal
       For x = 1 To 15
     puissance2 = puissance2 + Application.Power(Taux_CPrincpal, 0) + Application.Power(Taux_CPrincpal, x)
    Next x
End Function
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,405
Members
449,157
Latest member
mytux

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