ich möchte einen von mir markierten Bereich per Knopfdruck per Zufallsgenerator sortieren. Es sollte eine Art Auslosung werden.
Hoffe mir kann jemand helfen!
Danke im Voraus.
Sub teams()
Dim zuf(999) As Integer
Dim wert(999) As String
If Selection.Count <= 1 Then Exit Sub
For k = 0 To Selection.Count - 1
zuf(k) = Int(Rnd() * Selection.Count)
If k > 0 Then
For i = 0 To k - 1
If zuf(i) = zuf(k) Then
k = k - 1
Exit For
End If
Next
End If
wert(zuf(k)) = ActiveCell.Offset(k, 0)
Next k
For i = 0 To Selection.Count - 1
ActiveCell.Offset(i, 0) = wert(i)
Next
End Sub
Public Sub Zufall()
Dim varArray As Variant, varTemp As Variant
Dim lngIndex1 As Long, lngIndex2 As Long, lngAnzahl As Long
ReDim varArray(1 To Selection.Rows.Count * Selection.Columns.Count)
For lngIndex2 = Selection.Column To Selection.Column + Selection.Columns.Count - 1
For lngIndex1 = Selection.Row To Selection.Row + Selection.Rows.Count - 1
lngAnzahl = lngAnzahl + 1
varArray(lngAnzahl) = Cells(lngIndex1, lngIndex2)
Next
Next
For lngIndex1 = lngAnzahl To 1 Step -1
Randomize Timer
lngIndex2 = Int((lngIndex1 * Rnd) + 1)
varTemp = varArray(lngIndex2)
varArray(lngIndex2) = varArray(lngIndex1)
varArray(lngIndex1) = varTemp
Next
lngAnzahl = 0
For lngIndex2 = Selection.Column To Selection.Column + Selection.Columns.Count - 1
For lngIndex1 = Selection.Row To Selection.Row + Selection.Rows.Count - 1
lngAnzahl = lngAnzahl + 1
Cells(lngIndex1, lngIndex2) = varArray(lngAnzahl)
Next
Next
End Sub