Würfelwerte in Strings - Version 3
23.11.2009 14:28:38
NoNet
Hallo Chris,
jetzt habe ich das wohl korrekt verstanden - hier Version 3 :
Sub Wuerfel25Version3()
'23.11.2009, NoNet - www.excelei.de
Dim wuerfel()
Dim intS As Integer, intW As Integer, intZ As Integer, strTemp As String
'Deklaration der 25 Würfel per Strings :
wuerfel() = Array("ABCDEF", "DEFGHI", "ACXEMP", "YDMERS", "TBMNKL", _
"SEWACO", "UHNVIZ", "ADWERT", "EQXIJL", "LPODSM", _
"WSDAGH", "ASDSDF", "RWEPQW", "WREWEQ", "ASDGMS", _
"WFGHIJK", "ABCDEF", "GHIJKL", "MNOPQR", "STUVWX", _
"ZABCDE", "QWERTZ", "UIOPAS", "FGHJKL", "MNBVCX")
'Alternativ : Die Strings der Würfelwerte stehen in "Tabelle1", Bereich A1:A25 :
'wuerfel = Application.Transpose(Sheets("Tabelle1").[A1:A25])
'Würfel mischen :
For intS = LBound(wuerfel) To UBound(wuerfel)
intW = Int(Rnd() * UBound(wuerfel)) + LBound(wuerfel)
intZ = Int(Rnd() * UBound(wuerfel)) + LBound(wuerfel)
strTemp = wuerfel(intW)
wuerfel(intW) = wuerfel(intZ)
wuerfel(intZ) = strTemp
Next
Sheets("Tabelle2").Select
Cells.Clear 'Alle Zellen zuvor löschen - für Mehrfach-Start !
[A1] = "Matrix 5x5 :"
For intW = 1 To 25
'Würfeln und in passende Zelle der 5 x 5 Matrix schreiben :
intZ = Int(Rnd() * 6 + 1) 'die gewürfelte Zahl dieses Würfels
Cells((intW - 1) \ 5 + 1, (intW - 1) Mod 5 + 2) = _
Mid(wuerfel(intW - 1 + LBound(wuerfel)), intZ, 1)
Next
Columns.AutoFit
End Sub
GRuß, NoNet