AW: Lottoauswertung
18.08.2013 16:07:02
MathiasW.
Hallo Hajo,
ja das ist leider ein Makro Problem,
wenn ich den Wert in B4 auf 1 setzt und ein paar mal klicke,
wird L2 farblich markiert. Das heißt für mich, das diese Zelle
als Zufallszahl ausgewählt wird, obwohl sie nicht im Bereich
D4:J10 liegt. Also müsste der Code irgendwo einen Fehler haben.
Leider bin ich kein VBA Profi und würde mich über Hilfe sehr freuen.
das ist der betreffende Code
Private Sub CommandButton3_Click()
'Zufaelige Lottozahlen auswaehlen
On Error GoTo ErrMsg
Application.ScreenUpdating = False
Dim Lottozahl(25) 'max. Anzahl der Zahlen eingeben
Range("D4:J10").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 Range("B4") 'Zellenbezug B4
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 = 43 Then GoTo nochmal 'Hintergrundfarbe
With Selection.Interior
.ColorIndex = 43 'Hintergrundfarbe
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Next zähler%
'ab hier werden nur Tabellenformatieren zugefügt, ich schätze daher, dass der Fehler oben liegt
Range("D4:J10").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Color = -12654006
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -12654006
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -12654006
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Color = -12654006
.TintAndShade = 0
.Weight = xlThick
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("R14").Select
Exit Sub
ErrMsg:
MsgBox ("Was verstehst du an max. 25 nicht Dummpfbacke?"), , ";-)"
End Sub
Gruß
Mathias