Auch Hallo,
ich finde es brutal, ActiveX-CommandButtons zu nehmen. Hier mal ein Beispiel mit der Autoform Rechteck: (Da könnte man natürlich noch viel mehr formatieren und gestalten.)
Sub test_Kuwer()
Dim loA As Long
Dim loB As Long
Dim lozahl As Long
Dim loZahl2 As Long
Dim loC As Long
Dim CB As Shape
Dim strB As String
Dim strName As String
Dim arrZahlen, arrZahlen2(13)
With Sheets("Tabelle2")
Application.ScreenUpdating = False
.DrawingObjects.Delete
Do
Randomize
loC = Application.WorksheetFunction.RandBetween(1, 61)
If InStr(arrZahlen, loC) = 0 Then
arrZahlen = Format(loC, "00") & "," & arrZahlen 'Zufallszahlen in ein mit Leerzeichen getrennt in ein Array schreiben
arrZahlen2(loB) = loC
loB = loB + 1
End If
Loop While loB < 14
.Cells(1, 2).FormulaLocal = "=INDEX(Liste!1:1;ZUFALLSBEREICH(0;5)*2+1)"
.Cells(1, 2).Value = .Cells(1, 2).Value
For loA = 1 To 61
.Cells(1, 1).FormulaLocal = "=SVERWEIS(ZUFALLSBEREICH(1;200);INDEX(Liste!$1:$1;VERGLEICH($B$1;Liste!$1:$1;0)):INDEX(Liste!$26:$26;VERGLEICH($b$1;Liste!$1:$1;0)+1);2;1)"
strName = .Cells(1, 1)
Set CB = .Shapes.AddShape(msoShapeRectangle, 20, 20, 68.25, 56)
CB.ThreeD.ContourWidth = 0.2
CB.TextFrame2.TextRange.Text = strName
CB.Line.ForeColor.RGB = RGB(192, 192, 192)
CB.Fill.ForeColor.RGB = RGB(192, 192, 192)
CB.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
strB = Format(loA, "00")
If InStr(arrZahlen, strB) <> 0 Then
CB.Fill.ForeColor.RGB = RGB(0, 0, 255)
CB.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
'----------------------
If InStr(arrZahlen, loA) < 27 Then
CB.Fill.ForeColor.RGB = RGB(0, 0, 255)
CB.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
ElseIf InStr(arrZahlen, loA) < 38 Then
CB.Fill.ForeColor.RGB = RGB(200, 100, 0)
Else
CB.Fill.ForeColor.RGB = RGB(100, 100, 100)
End If
End If
' -------------------------------
If loA < 6 Then
CB.Top = 30
CB.Left = 259 + (loA - 1) * 69
ElseIf loA < 12 Then
CB.Top = 90
CB.Left = 259 + (loA - 6) * 69 - 34
ElseIf loA < 19 Then
CB.Top = 150
CB.Left = 259 + (loA - 13) * 69
ElseIf loA < 27 Then
CB.Top = 210
CB.Left = 259 + (loA - 20) * 69
ElseIf loA < 36 Then
CB.Top = 270
CB.Left = 259 + (loA - 29) * 69
ElseIf loA < 44 Then
CB.Top = 330
CB.Left = 259 + (loA - 37) * 69 - 34
ElseIf loA < 51 Then
CB.Top = 390
CB.Left = 259 + (loA - 45) * 69
ElseIf loA < 57 Then
CB.Top = 450
CB.Left = 259 + (loA - 51) * 68.25 - 34
Else
CB.Top = 510
CB.Left = 259 + (loA - 57) * 68.25
End If
Next
.Range("a1").Clear
.Range("M2") = "Doppelklick hier!"
End With
Application.ScreenUpdating = True
Exit Sub
Fehler: MsgBox (Err.Number & " " & Err.Description & "--> Button " & loA & " " & strName & " " & arrZahlen)
End Sub
Gruß Uwe