```
Sub rdm()
Dim cell As Range, MyRanRng, x, nDec As Integer
Dim K As Long, iFlag As Boolean
Dim i As Integer, j As Integer, n As Integer
Dim NosAvailable As Long
Dim ArrayOfValues
MyRanRng = Application.InputBox(prompt:="Enter lower and upper limits separated by space", _
Title:="Enter number range")
If TypeName(MyRanRng) = "Boolean" Then Exit Sub
x = Split(MyRanRng)
If Not IsArray(x) Then Exit Sub
nDec = Application.InputBox(prompt:="No. decimal places", Title:="Enter decimal places", Type:=1)
If TypeName(nDec) = "Boolean" Then nDec = 0
K = Selection.Cells.Count
NosAvailable = (x(UBound(x)) - x(LBound(x))) * 10 ^ nDec + 1
If K > NosAvailable Then
MsgBox prompt:="Cells available:" & vbTab & K & vbCrLf & "Numbers available:" & _
vbTab & NosAvailable & vbCrLf & vbCrLf & _
"Select a smaller range or increase the number range", _
Title:="Error trap!", Buttons:=vbOKOnly + vbCritical
Exit Sub
End If
Randomize
ReDim ArrayOfValues(1 To K) As Variant
For i = 1 To K
Do
iFlag = False
ArrayOfValues(i) = Round(Rnd() * (x(UBound(x)) - x(LBound(x))) + x(LBound(x)), nDec)
For n = 1 To i - 1
If ArrayOfValues(i) = ArrayOfValues(n) Then iFlag = True
Next n
Loop Until iFlag = False
Next i
j = 0
For Each cell In Selection
j = j + 1
cell.Value = ArrayOfValues(j)
Next cell
End Sub
```