
Option Explicit
Sub mescola_range()
Dim r As Range, i As Integer
Dim r1 As Integer, r2 As Integer, tmp As Integer
Randomize Timer
Set r = Range("A1:A40")
For i = 1 To 1000 'numero di estrazioni
r1 = Int(Rnd * 40) + 1
r2 = Int(Rnd * 40) + 1
'swap celle
tmp = Cells(r1, "A")
Cells(r1, "A") = Cells(r2, "A")
Cells(r2, "A") = tmp
Next
End Sub |
Sub RandomRange()
Dim i As Integer, j As Integer, temp As Integer, arr(), first As Integer, last As Integer
arr = Range("A1:A40").Value
last = UBound(arr)
first = 1
For i = last To first Step -1
j = Rnd * (last - first + 1) + first
If j > last Then j = last
temp = arr(i, 1)
arr(i, 1) = arr(j, 1)
arr(j, 1) = temp
Next
Range("A1:A40") = Application.Transpose(Application.Transpose(arr))
End Sub |
Public Sub Casual40() |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
