Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!

Looking for VBA Exc...
Clear all

Looking for VBA Excel support

Active Member
Joined: 4 months ago
Posts: 9
Topic starter  

Mayby this isnt the right spot for this , but i could use somehelp with visual basic exel :D


Basicly this is the thing that i have to turn into macro, have to use Do and For operators.

I have trouble finding out what should i put for limit.

Help would be highly appreaciated :)

Topic Tags
Noble Member Admin
Joined: 8 years ago
Posts: 1767

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


Active Member
Joined: 4 months ago
Posts: 9
Topic starter  

Thank you very much this helped alot, my task was to make 2 macros one with do second with for, wil try to use this info to make thouse :)



Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).