Question: I tried to write this formula excel vba what is my wrong

```
For i = 1 To (N - 1)
    H = H + N- (i / (N) ^ P)
Next

```

[![enter image description here](https://i.stack.imgur.com/WYgWl.jpg)](https://i.stack.imgur.com/WYgWl.jpg)

Answer: 
If you want a formula to do it:

```
=B1 -SUMPRODUCT((ROW($ZZ1:INDEX($ZZ:$ZZ,B1-1))/B1)^B2)

```

[![enter image description here](https://i.stack.imgur.com/qiS8E.png)](https://i.stack.imgur.com/qiS8E.png)
For caulations, VBA follows operator precedence, so we should carefully use parentheses around the calculations in order to change the predence of operators. Absence of parentheses at the right place in the above caluclations could be the reason of unexpected result. Please refer to the link below to see the operator precendence:

<https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/operator-precedence>