ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Randomizing Hell (https://www.excelbanter.com/excel-programming/317401-randomizing-hell.html)

Arturo

Randomizing Hell
 
Hello €“

I pick up a percentage from a given cell and based on some preset variance,
say +/-10%, I need to randomly assign a new percentage to a block of cells
elsewhere, based on that drivers range. So if the driver is 30% and the
variance is +/-10% the range to randomly be applied to a block of cells
elsewhere would be between 27%, 28%, 29%... to 33%. Each cell in that block
getting a random number from that range. I have most of the looping
components down; I just keep tripping over the above scenario and am not
finding the pieces to put together.

Any direction is greatly appreciated.
Sincerely,
Arturo

John Green[_4_]

Randomizing Hell
 
Arturo,

Te following code shows how to calculate your random numbers:

Sub GenRand()
Dim Driver As Double
Dim Var As Double
Dim Result As Double

Driver = 0.3
Var = 0.1

Result = (1 - Var) * Driver + 2 * Rnd() * Var * Driver

MsgBox Result

End Sub

(1-Var)*Driver gives you the 27% base you need.

2*Var*Driver gives you the 6% range to be added. Applying Rnd() to this
gives a random number in the range.

--
John Green
Sydney
Australia


"Arturo" wrote in message
...
Hello -

I pick up a percentage from a given cell and based on some preset

variance,
say +/-10%, I need to randomly assign a new percentage to a block of cells
elsewhere, based on that driver's range. So if the driver is 30% and the
variance is +/-10% the range to randomly be applied to a block of cells
elsewhere would be between 27%, 28%, 29%... to 33%. Each cell in that

block
getting a random number from that range. I have most of the looping
components down; I just keep tripping over the above scenario and am not
finding the pieces to put together.

Any direction is greatly appreciated.
Sincerely,
Arturo





All times are GMT +1. The time now is 02:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com