Q:

Computing sums on VBA

Trying to sum 2^i from i=0 to i=n on VBA. Where n is an entered value by the user each time
I can get it to do each term individually but its not summing.
Sub Button1()
Dim n As Single

n = InputBox("Enter a value for n")

Dim array as

Dim CSeriesSum As Double

ActiveCell.Value = WorksheetFunction.SeriesSum(Arg1:=2, Arg2:=n, Arg3:=1, Arg4:=1:n)

End Sub

I expect it to return for eg. 1 if n=0, 3 if n=1, 7 if n=2 etc.

A:

Maybe try this loop:
Sub Button1()

Dim n As Single

n = InputBox("Enter a value for n")

Dim val As Long

    val = 0
    For i = 0 To n

        val = val + 2 ^ i

    Next

ActiveCell.Value = val

End Sub

