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: 
The loop is only for what is behind the sum sign `Σ` and the `N - Σ` must be calculated **after** the loop. Also you need to place the perenthesis correctly:

```
Public Function H(ByVal N As Long, ByVal P As Double) As Double
    'Calculate the sum Σ
    Dim S As Double 'result of the sum Σ
    Dim i As Long
    For i = 1 To (N - 1)
        S = S + ((i / N) ^ P)
    Next

    'Then calculate the rest
    H = N - S
End Function

```
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)