RANDOMNUMBER

Returns random numbers between the two bounds.

'lLowestValue - The lowest value.
'lHighestValue - The highest value.
'iNoOfDecimals - (Optional) The number of decimal places.

Public Function RANDOMNUMBER(ByVal lLowestValue As Long, _
                             ByVal lHighestValue As Long, _
                Optional ByVal iNoOfDecimals As Integer) As Variant

   Application.Volatile
   VBA.Randomize
   If (IsMissing(iNoOfDecimals) Or (iNoOfDecimals = 0)) Then
      RANDOMNUMBER = VBA.Int((lHighestValue + 1 - lLowestValue) * VBA.Rnd + lLowestValue)
   Else
      RANDOMNUMBER = VBA.Round((lHighestValue - lLowestValue) * VBA.Rnd + lLowestValue, iNoOfDecimals)
   End If

   RANDOMNUMBER = VBA.Cdec(RANDOMNUMBER)
End Function

This function returns a random number that changes when you press F9.
If you don't want the random number to keep changing then remove the "Application.Volatile" statement.
Do not enter this function as an array formula, otherwise all the random numbers will be the same.
Enter the formula into one cell and drag it to all the cells in your range.
The maximum number of decimal places is 9.
The largest number is 7 digits 1,000,000.


This function allows you to specify a lower limit, an upper limit and the number of decimal places for the generated random number.
Include SS - randoms between (0,1,3)
Include SS - randoms between (-50,-100,2)


RANDOMNUMBER_STATIC





© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext