loop of this formula

kingman29

Board Regular
Joined
Jun 22, 2021
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Hello
I have a Monster function,
is that possible to make this function inVBA ?
A1 = 15%
B1 = +POWER(A1;1)-POWER(A1;2)-POWER(A1;3)-POWER(A1;4)-POWER(A1;5)
witch mean every time we subtract A1 with the increase of power

So My Vba code is :
VBA Code:
Sub Calculate()
Range("B1") = Range("A1") ^ 1 - Range("A1") ^ 2 - Range("A1") ^ 3 - Range("A1") ^ 4 - Range("A1") ^ 5 - Range("A1") ^ 6

End Sub
Is that anyway to make this Code more professional ?
what If I have Power of 56 times ?
Thank you *
note : My windows and Office in French Language
 

Attachments

  • resultat.png
    resultat.png
    150.2 KB · Views: 9

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
@JackDanIce, I owe you an apology since I was terribly wrong :eek::cry:

I should have looked into this further but didn't. The moment I would post my contribution I saw there were already enough possible solutions, so I didn't post it. When I read the OP had discovered a difference in the end result, while the end result of my solution (also a UDF) matched his, I noticed the difference in argument declaration. My premature conclusion was that this had to be the cause (indeed on account of type conversion), but nothing could be further from the truth!!

If I put your post #2 code and my code together (and use the same variable names for better comparison) I think I don't need to explain anything further. Cheers.
Rich (BB code):
Public Function MyFunction(my_input As Double, my_power As Long) As Double
   
    ' JackDanIce
    Dim x As Long
    MyFunction = my_input
    For x = 2 To my_power
        MyFunction = MyFunction - MyFunction ^ x
    Next x
End Function


Public Function MyFunction(my_input As Range, my_power As Range) As Double
   
    ' GWteB
    Dim x As Long
    MyFunction = my_input.Value
    For x = 2 To my_power.Value
        MyFunction = MyFunction - my_input.Value ^ x
    Next x
End Function
Yeah I noticed that too and made change afterwards lol The construct/intention of both was same, sloppy mistake on my part
 
Upvote 0

Forum statistics

Threads
1,215,232
Messages
6,123,765
Members
449,121
Latest member
Vamshi 8143

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