Monday, January 24, 2011

VBA Code for Random Generation of Stats

CoinToss()

Dim x As Integer
Dim Row as Integer
Dim NumberOfFunds As Integer

erOfFunds = Sheets("Sheet1").Range("NumberOfPeople")

Worksheets("Sheet1").Range("ClearNumber").Select
Selection.ClearContents----------------------------Clears data from cells

For x = 1 To NumberOfFunds-------------Starts loop

Application.ScreenUpdating = False--------------Stops flickering of screen

Calculate-------------------------------This calculates the random generation function
Range("Future1").Select
Selection.copy
Range("Option1").Offset(x, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkpBlanks _
:=False, Transpose:=False

Range("Future2").Select
Selection.copy
Range("Option2").Offset(x, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Next

Range("M10:N109").Select----------------------This formats the numbers that are generated
Application.CutCopyMode = False
Selection.NumberFormat = "0.0000"
Selection.NumberFormat = "0.000"
Selection.NumberFormat = "0.00"
Selection.NumberFormat = "0.0"
Selection.NumberFormat = "0"

Range("A1").Select------------------ends macro in cell a1

Sub

No comments:

Post a Comment