Hi rdiizz,
I haven't touched VBA for Excel ever (this is seems a good start).
As for your formula: Is this an open formula where we pass n and x ? Or does it really stop at 10x^9 ?
Usually this can be solved without do/for loops by doing the math (see for example here how math experts explain this - Scroll down to the explanation of Bikki Chhantyal).
But since you're asking specifically for loops, naturally you could use a for-loop as well ...
In pseudo code (so this is not real code and just illustrates the steps - since I am not familiar enough with VBA for Excel, so I'm basing this loosely what I remember from VBA in general):
Assuming an input of "x" and "n":
Public Function MyFormula(x As Integer, y As Integer)
MyFormula = 0
for Counter= 1 to n do
MyFormula = MyFormula + Counter*( x^( Counter-1 ) )
Next Counter
End Function
Again: this may not be 100% correct notation, I had to write this from memory from way back in the day.
You may need to modify it a little bit to make it work in VBA Excel.
So for your example n=10 (the picture you posted counts to 10), you'd call the function MyFunction(x,10).
Note here:
if Counter=1 then the result will be 1 (as seen in your formula), no matter what X you entered, since X^0 = 1.
So in the code 1 * X^(1-1) = 1 * X^0 = 1 * 1 = 1.
if Counter=2 then the result will be: 2 * X^(2-1) = 2 * X^1 = 2 * X
if Counter=3 then the result will be: 3 * X^(3-1) = 3 * X^2
etc.