Microsoft Excel training videos


Random Function RAND() in Excel

When you type the formula =RAND() in an Excel worksheet cell, you get a decimal number between 0 and 1. If you have a good amount of data, say, in about 1000 Excel cells, you can calculate that 25% of the time the value of the number is less than or equal to 0.25; around 10% of the time the number is around 0.90. I've created a macro to determine the fractions between 0 and 0.25, 0.25 and 0.50, 0.50 and 0.75 and 0.75 to 1. You will notice that the average of the 1000 numbers is always about 0.5 and intervals of 0.25 have 25% of the total values. Also note that the values generated by the RAND function are independent. What is the importance of such random values? Well, as we shall see in the next video, you can connect such random numbers with probabilities of demand for a product or service and perform a Monte Carlo simulation of your data.

The macro to calculate the fractions is given below for your ready reference:

Sub fractions()
x = 2
Do While Cells(x, 2) <> ""
If Cells(x, 2) > 0.75 Then
Count = Count + 1
ElseIf Cells(x, 2) >= 0.5 And Cells(x, 2) < 0.75 Then
count2 = count2 + 1
ElseIf Cells(x, 2) >= 0.25 And Cells(x, 2) < 0.5 Then
count3 = count3 + 1
Else
count4 = count4 + 1
End If
x = x + 1
Loop
Range("E2") = count4 / 1000
Range("E3") = count3 / 1000
Range("E4") = count2 / 1000
Range("E5") = Count / 1000

End Sub

 


RANDOM function in Excel