Is your equation for S correct? It looks like it should be:
S = M * CB * (p ^ i) ...
instead
S = M * CB * (p ^ n) ...
If your equation is really wrong, you can use BINOMDIST instead of COMBIN, because by definition:
Binom_Dist(i, n, p, False) = (p ^ i) * (1 - p) ^ (n - i) * Combin(n, i)
So your code will look like this:
S = M * WorksheetFunction.Binom_Dist(i, n, p, False)
instead
CB = WorksheetFunction.Combin(n, i)
S = M * CB * (p ^ n) * (1 - p) ^ (n - i)
BINOMDIST is not so sensitive to large n, i.
source
share