Buona sera, Ema.Cab;
la struttura del Codice VBA è, più o memo, sempre la stessa.
In questo caso, ho definito tre costanti:
- PRg As Byte = 15 ---> Prima riga
- URg As Byte = 31 ---> Ultima riga
- Cln As Byte = 27 ---> Colonna nella quale sono inseriti i Valori
Option Explicit
Sub Random_n()
Application.ScreenUpdating = False
Const PRg As Byte = 15
Const URg As Byte = 31
Const Cln As Byte = 27
Dim lNum As Byte, r As Byte, n As Byte, NVis As Byte
Dim nxx As Integer
Dim arNum() As Byte
Dim j As Integer
Range(Cells(PRg, Cln + 2), Cells(URg, Cln + 2)).ClearContents
lNum = URg - PRg + 1
NVis = Cells(15, 34).Value
ReDim arNum(1 To lNum)
For j = 1 To lNum
arNum(j) = Cells(j + PRg - 1, Cln).Value
Next j
nxx = 1
For j = lNum To 1 Step -1
r = Int((j * Rnd) + 1)
n = arNum(r)
arNum(r) = arNum(j)
arNum(j) = n
Cells(nxx + PRg - 1, Cln + 2) = arNum(j)
nxx = nxx + 1
If nxx > NVis Then Exit For
Next j
Erase arNum
Application.ScreenUpdating = True
End Sub
A disposizione.
Buona serata.
Giuseppe
Windows XP - Excel 2000
Windows 10 - Excel 2013