Please see VBA code below. The loop runs fine when I run the random number generator function (RandBetween) alone, but crashes when I wrap it with the beta probability function