Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao vorget,
Ecco mio ultimo suggerimento che riempe l'intervallo selezionato da te, evitando la presenza di doppioni nelle righe:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim destRng As Range, srcRng As Range
Dim arrIn As Variant, arrShuffled() As Variant
Dim arrUnique() As Variant
Dim i As Long
Const sFoglio As String = "Foglio1" '<<=== Modifica
Const sIntervalloSorgente As String = "G5:K6"
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
Set srcRng = SH.Range(sIntervalloSorgente).CurrentRegion
Set destRng = Application.InputBox( _
Prompt:="Seleziona o digita l'intervallo di elaborazione", _
Type:=8, _
Title:="Intervallo di Elaborazione Casuale")
arrIn = srcRng.Value
arrUnique = SortedUniqueList(arrIn)
With destRng
.CurrentRegion.ClearContents
For i = 1 To .Rows.Count
arrShuffled = ShuffleArray(arrUnique)
.Rows(i).Value = arrShuffled
Next i
End With
XIT:
End Sub
'--------->>
Public Function SortedUniqueList(V As Variant)
Dim oSortedUniqueList As Object
Dim arrOut() As Variant
Dim iVal As Long
Dim i As Long, j As Long
Set oSortedUniqueList = CreateObject("System.Collections.Sortedlist")
With oSortedUniqueList
For i = LBound(V) To UBound(V)
For j = 1 To UBound(V, 2)
iVal = V(i, j)
If Not iVal = 0 Then
If Not .ContainsKey(iVal) Then
.Add Key:=iVal, Value:=i
End If
End If
Next j
Next i
ReDim arrOut(1 To .Count)
For i = 0 To .Count - 1
arrOut(i + 1) = .GetKey(i)
Next i
End With
SortedUniqueList = arrOut
End Function
'--------->>
Public Function ShuffleArray(InArray() As Variant) As Variant()
Dim N As Long
Dim Temp As Variant
Dim j As Long, L As Long
Dim Arr() As Variant
Randomize
L = UBound(InArray) - LBound(InArray) + 1
ReDim Arr(LBound(InArray) To UBound(InArray))
For N = LBound(InArray) To UBound(InArray)
Arr(N) = InArray(N)
Next N
For N = LBound(InArray) To UBound(InArray)
j = CLng(((UBound(InArray) - N) * Rnd) + N)
Temp = Arr(N)
Arr(N) = Arr(j)
Arr(j) = Temp
Next N
ShuffleArray = Arr
End Function
'<<=========
===
Regards,
Norman