I've just been messing around on VBA and am trying to write a summation that estimates pi. It doesn't add anything to the sum within the do while. I tried a for loop also, but it just takes whatever i initialize sum to and multiplies it by 4 and adds one. I just want it to add continually to sum the new values of n given j. Need help it seems like such a simple problem...(adsbygoogle = window.adsbygoogle || []).push({});

Sub pi()

Dim j As Integer

Dim sum As Integer

Dim n As Integer

sum = 0

j = 2

Do While j <= 100

n = (1 / (2 * j - 1)) * ((-1) ^ (2 * j - 1))

sum = sum + n

j = j + 1

Loop

sum = 4 * sum + 1

Range("E2:E100").Cells(2).Value = sum

End Sub

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# VBA not calculating how I want it to

Loading...

Similar Threads - calculating | Date |
---|---|

Symbolic calculations in MATLAB | Nov 21, 2017 |

Python Insert data into excel, calculate+retrieve data using Python | Sep 3, 2017 |

How to calculate the capacity of a disk | Mar 23, 2017 |

Monte Carlo Calculation of π | Mar 17, 2017 |

**Physics Forums - The Fusion of Science and Community**