wer hat eine möglichst effektive Idee (VBA-Idee) die Variable Lotto(6) mit sechs zufällig (aber unterschiedlichen) Lottozahlen zu füllen?
Habe wohl zu viel Rindfleisch gegessen: mir fällt nichts schnelles ein.
Liebe Grüße Vera
Sub LottoZufall()
Dim Lottozahl(6), Schleife, Zahl As Byte
Schleife = 1
Do
Zahl = Int((49) * Rnd + 1)
If Zahl <> Lottozahl(1) And _
Zahl <> Lottozahl(2) And _
Zahl <> Lottozahl(3) And _
Zahl <> Lottozahl(4) And _
Zahl <> Lottozahl(5) And _
Zahl <> Lottozahl(6) Then
Lottozahl(Schleife) = Zahl
Schleife = Schleife + 1
End If
Loop Until Schleife > 6
End Sub
Sub LottoZufall()
Dim Lottozahl(6), Schleife, Zahl As Byte
Schleife = 1
For Schleife = 1 To 6
Zahl = Int((49) * Rnd + 1)
If Zahl <> Lottozahl(1) And _
Zahl <> Lottozahl(2) And _
Zahl <> Lottozahl(3) And _
Zahl <> Lottozahl(4) And _
Zahl <> Lottozahl(5) And _
Zahl <> Lottozahl(6) Then
Lottozahl(Schleife) = Zahl
Else
Schleife = Schleife - 1
End If
Next
End Sub
Sub Lotto()
Dim Zahlen(6) As Byte
Dim Zahl As Byte
Dim ZNr As Byte
Dim i As Byte
Zahlen(1) = Fix(Rnd * 49) + 1
For ZNr = 2 To 6
Zahl = Fix(Rnd * 49) + 1
For i = 1 To ZNr - 1
If Zahl = Zahlen(i) Then
Zahlen(ZNr) = 1
Exit For
End If
Next
Zahlen(ZNr) = Zahlen(ZNr) + Zahl
Next
End Sub
Sub lottozahlen()
Dim kugeln() As Byte
Dim lotto(5) As Byte
ReDim kugeln(48)
For i = 0 To 48
kugeln(i) = i + 1
Next i
For i = 0 To 5
zufall = Int((49 - i) * Rnd + 1)
lotto(i) = kugeln(zufall)
For j = zufall To 48 - 1 - i
kugeln(j) = kugeln(j + 1)
Next j
ReDim Preserve kugeln(47 - i)
Next i
End Sub
Sub Lotto()
Application.ScreenUpdating = False
Dim Lottozahl(6)
Range("A3:G9").Select
With Selection
.Borders(xlLeft).LineStyle = xlNone
.Borders(xlRight).LineStyle = xlNone
.Borders(xlTop).LineStyle = xlNone
.Borders(xlBottom).LineStyle = xlNone
.BorderAround LineStyle:=xlNone
.Interior.ColorIndex = xlNone
End With
Range("A1").Select
For zähler% = 1 To 6
Randomize Timer
nochmal:
Lottozahl(zähler%) = Int((49) * Rnd + 1)
Cells.Find(What:=Lottozahl(zähler%)).Activate
Selection.BorderAround Weight:=xlThin, ColorIndex:=xlAutomatic
If Selection.Interior.ColorIndex = 35 Then GoTo nochmal
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Next zähler%
End Sub
Sub Lotto()
Dim I As Byte
For I = 0 To 48
[iv65536].Offset(-I, 0) = Rnd
Next I
For I = 0 To 5
Cells(I + 1, [iv6].End(xlToLeft).Column + 1) = Application.WorksheetFunction.Rank([iv65536].Offset(-I, 0), [iv65488:iv65536])
Next I
[iv65488:iv65536].ClearContents
End Sub
Sub Lotto()
Dim Zahlen(6) As Byte
Dim blnZ(49) As Boolean
Dim Zahl As Byte
Dim ZNr As Byte
Do
Zahl = Fix(Rnd * 49) + 1
If blnZ(Zahl) = False Then
blnZ(Zahl) = True
ZNr = ZNr + 1
Zahlen(ZNr) = Zahl
End If
Loop Until ZNr = 6
End Sub
Um einen Excel Lottozahlen Generator mit VBA zu erstellen, folge diesen Schritten:
Öffne Excel und drücke ALT + F11, um den VBA-Editor zu öffnen.
Klicke auf "Einfügen" und dann auf "Modul", um ein neues Modul zu erstellen.
Kopiere und füge den folgenden Code in das Modul ein:
Sub LottoZufall()
Dim Lottozahl(6) As Byte
Dim Schleife As Byte
Dim Zahl As Byte
Schleife = 1
Do
Zahl = Int((49) * Rnd + 1)
If Not (Zahl = Lottozahl(1) Or Zahl = Lottozahl(2) Or _
Zahl = Lottozahl(3) Or Zahl = Lottozahl(4) Or _
Zahl = Lottozahl(5) Or Zahl = Lottozahl(6)) Then
Lottozahl(Schleife) = Zahl
Schleife = Schleife + 1
End If
Loop Until Schleife > 6
' Ausgabe der Lottozahlen
For i = 1 To 6
Cells(1, i).Value = Lottozahl(i) ' Ausgabe in Zeile 1
Next i
End Sub
Schließe den VBA-Editor und kehre zu Excel zurück.
Führe das Makro aus, indem du ALT + F8 drückst und das Makro "LottoZufall" auswählst.
Die generierten Lottozahlen werden in die ersten sechs Zellen der ersten Zeile ausgegeben.
Fehler 1: Doppelte Zahlen werden nicht ausgeschlossen
If Not-Bedingung wie im obigen Beispiel.Fehler 2: Fehlermeldung beim Ausführen des Makros
Es gibt mehrere Ansätze, um Lottozahlen mit Excel zu generieren:
Mit einer Excel-Formel: Du kannst die Funktion =ZUFALLSBEREICH(1;49) verwenden, um zufällige Zahlen zu erhalten, jedoch musst du sicherstellen, dass keine doppelten Werte auftreten.
VBA-Alternativen: Es gibt viele Ansätze, wie den von Micha, der ein Array verwendet, um die Zufallszahlen effizient zu generieren. Hier ein Beispiel:
Sub lottozahlen()
Dim kugeln() As Byte
Dim lotto(5) As Byte
Dim zufall As Integer
ReDim kugeln(48)
For i = 0 To 48
kugeln(i) = i + 1
Next i
For i = 0 To 5
zufall = Int((49 - i) * Rnd + 1)
lotto(i) = kugeln(zufall)
For j = zufall To 48 - 1 - i
kugeln(j) = kugeln(j + 1)
Next j
ReDim Preserve kugeln(47 - i)
Next i
End Sub
Hier sind zwei praktische Beispiele für einen Lottozahlen Generator:
Einfacher Lottozahlen Generator:
Erweiterter Lottozahlen Generator:
Sub Lotto()
Dim Zahlen(6) As Byte
Dim blnZ(49) As Boolean
Dim Zahl As Byte
Dim ZNr As Byte
Do
Zahl = Fix(Rnd * 49) + 1
If blnZ(Zahl) = False Then
blnZ(Zahl) = True
ZNr = ZNr + 1
Zahlen(ZNr) = Zahl
End If
Loop Until ZNr = 6
End Sub
Application.ScreenUpdating = False, um die Ausführungsgeschwindigkeit zu erhöhen, wenn du große Datenmengen bearbeitest.1. Wie kann ich die Wahrscheinlichkeit von Lottozahlen auswerten?
Du kannst die Wahrscheinlichkeit von Lottozahlen mit Excel-Formeln und Datenanalysen auswerten. Nutze Funktionen wie HÄUFIGKEIT und Diagramme zur visuellen Darstellung.
2. Gibt es kostenlose Downloads für Lottozahlen Generatoren? Ja, auf Seiten wie die lottozahlen.net oder spezielle Foren findest du oft kostenlose Downloads für Lottozahlen Generatoren. Achte darauf, die Quelle zu überprüfen, um sicherzustellen, dass es sich um vertrauenswürdige Software handelt.