A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Sub CopyDataRandom()
Const xTitleId = "Lottery"
Dim InputRng As Range, OutRng As Range
Dim DataIn, DataOut
Dim a As Long, b As Long, c As Long, d As Long
'Exit if the user aborts
On Error GoTo Exitpoint
Set InputRng = Application.InputBox("Range :", xTitleId, Selection.Address(0, 0), Type:=8)
Set OutRng = Application.InputBox("Out put to (single cell):", xTitleId, Type:=8)
On Error GoTo 0
'Read in all values
DataIn = InputRng.Value
'More then one value?
If Not IsArray(DataIn) Then
'No
OutRng(1, 1).Value = DataIn
Else
'Create space for the output
ReDim DataOut(1 To UBound(DataIn), 1 To UBound(DataIn, 2))
'Initialize
Randomize
'For each input value
For a = 1 To UBound(DataIn)
For b = 1 To UBound(DataIn, 2)
'Find a random free space
Do
c = Rnd * (UBound(DataIn) - 1) + 1
d = Rnd * (UBound(DataIn, 2) - 1) + 1
Loop Until IsEmpty(DataOut(c, d))
'Store
DataOut(c, d) = DataIn(a, b)
Next
Next
'Write back
OutRng.Resize(UBound(DataIn), UBound(DataIn, 2)).Value = DataOut
End If
Exitpoint:
End Sub