Liebe Community,
ich habe versucht eine Schiebepuzzle aus Zahlen in Excel zu programmieren. Den Text seht ihr unten. Jedoch sobald ich auf Ausführen (Wiedergabe-Button) drücke, kommt folgender Fehler:
Laufzeitfehler '424':
Objekt erforderlich
Könnt ihr mir bitte helfen den Fehler zu finden?
Vielen Dank im Vorraus
Lamio13
Dim xpos As Integer
Dim ypos As Integer
Dim AlleKnoepfe(1 To 15) As CommandButton
Private Sub UserForm_Initialize()
Set AlleKnoepfe(1) = CommandButton1
Set AlleKnoepfe(2) = CommandButton2
...
Set AlleKnoepfe(14) = CommandButton14
Set AlleKnoepfe(15) = CommandButton15
End Sub
Sub FindMich(ich As String)
Dim ii As Integer
Dim jj As Integer
For jj = 1 To 4
For ii = 1 To 4
If (Cells(jj, ii) = ich) Then
xpos = ii
ypos = jj
ii = 5
jj = 5
End If
Next ii
Next jj
End Sub
Private Sub KannMichBewegen()
'untersuche, ob rechts frei ist
If (Cells(ypos, xpos + 1) = "") Then
Cells(ypos, xpos + 1) = Cells(ypos, xpos)
Cells(ypos, xpos + 1) = ""
End If
End Sub
Sub VerschiebMich(SchubladenNummer As Integer)
'untersuche, ob rechts frei ist
If (xpos < 4) Then
If (Cells(ypos, xpos + 1) = "") Then
Cells(ypos, xpos + 1) = Cells(ypos, xpos)
Cells(ypos, xpos) = ""
AlleKnoepfe(SchubladenNummer).Left = AlleKnoepfe(SchubladenNummer).Left + AlleKnoepfe(SchubladenNummer).Width
End If
End If
'untersuche, ob unten frei ist
If (ypos < 4) Then
If (Cells(ypos + 1, xpos) = "") Then
Cells(ypos + 1, xpos) = Cells(ypos, xpos)
Cells(ypos, xpos) = ""
AlleKnoepfe(SchubladenNummer).Top = AlleKnoepfe(SchubladenNumemr).Top + AlleKnoepfe(SchubladenNummer).Height
End If
End If
'untersuche, ob links frei ist
If (xpos > 1) Then
If (Cells(ypos, xpos - 1) = "") Then
Cells(ypos, xpos - 1) = Cells(ypos, xpos)
Cells(ypos, xpos) = ""
AlleKnoepfe(SchubladenNummer).Left = AlleKnoepfe(SchubladenNummer).Left + AlleKnoepfe(SchubladenNummer).Width
End If
End If
'untersuche, ob oben frei ist
If (ypos > 1) Then
If (Cells(ypos - 1, xpos) = "") Then
Cells(ypos - 1, xpos) = Cells(ypos, xpos)
Cells(ypos, xpos) = ""
AlleKnoepfe(SchubladenNummer).Top = AlleKnoepfe(SchubladenNumemr).Top + AlleKnoepfe(SchubladenNummer).Height
End If
End If
End Sub
Private Sub CommandButton1_Click()
FindMich (CommandButton1.Caption)
VerschiebMich (1)
End Sub
...