Gruppe
Allgemein
Bereich
Zufall
Thema
Nach dem Zufallsprinzip umsortieren
Problem
Wie kann ich eine Liste mit Werten nach dem Zufallsprinzip umsortieren?
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: basMain
Sub Zufall()
Dim rngA As Range
Dim iRow As Integer, iZufall As Integer
Randomize
iRow = Selection.Rows.Count
Columns(2).ClearContents
For Each rngA In Selection.Cells
iZufall = Int((iRow * Rnd) + 1)
Do While Not IsEmpty(Cells(iZufall, 2))
iZufall = Int((iRow * Rnd) + 1)
Loop
Cells(iZufall, 2).Value = rngA.Value
Next rngA
End Sub