Clever-Excel-Forum

Normale Version: elseif in VBA Code
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo zusammen,

ich beschäftige mich das erste mal mit VBA, aber da ich schon Bash Skripte und co geschrieben habe dachte ich das kann nicht so schwehr sein.

Aber jetzt hänge ich :

Code:
Private Sub G1_Click()

If Cells(59, 23).Value = "0" Then
    MsgBox "Bitte erst Spieler zum Board!"
Else
    If Cells(23, 4).Value = "0" And Cells(23, 5).Value = "0" Then
        If Cells(59, 23).Value = "1" And Cells(23, 7).Value = 0 Then
            Range("G23").Value = 1
            Range("W63").Value = 1
        ElseIf Cells(59, 23).Value = "1" Then
            Range("G23").Value = Range("G23").Value + 1
            Range("W63").Value = Range("W63").Value + 1
        End If
    ElseIf Cells(24, 4).Value = "0" And Cells(24, 5).Value = "0" Then
        If Cells(59, 23).Value = "2" And Cells(24, 7).Value = 0 Then
            Range("G24").Value = 1
            Range("W63").Value = 1
        ElseIf Cells(59, 23).Value = "2" Then
            Range("G24").Value = Range("G24").Value + 1
            Range("W63").Value = Range("W63").Value + 1
            Range("W65").Value = 1
        End If
    ElseIf Cells(23, 4).Value = 1 Or Cells(23, 5).Value = 1 Then
        MsgBox "Spiel Fertig!"
    End If
End If
End Sub


In das zweite elsif läuft er nicht rein :

    ElseIf Cells(23, 4).Value = 1 Or Cells(23, 5).Value = 1 Then       
MsgBox "Spiel Fertig!
"


Wenn ich auf den Button drücke fürt er das erste "if" aus
drücke ich nochmal läuft as erste elseif

Danach steht in D23 oder E23 eine 1 und er müsste beim dritten mal Drücken in das zweite elsif laufen, was er aber nicht macht.

alles schon versucht mit ""ohne, anderes Zellen Format....

Wo liegt mein Fehler ?

Danke schon mal
Hallo,

das ist ein Text.

"1"

PHP-Code:
Value "1" And Cells(237).Value 0 Then 
Hi Gastlich,

59, 23  ist auch text.

Es geht ja um das untere Elsif

    ElseIf Cells(23, 4).Value = 1 Or Cells(23, 5).Value = 1 Then  

Aber egal ob in "1" oder nicht geht es nicht.

Habe ich nur IF, Elsif, ging es.


Dann kam der Block dazischen der auch läuft :

Code:
    ElseIf Cells(24, 4).Value = "0" And Cells(24, 5).Value = "0" Then
        If Cells(59, 23).Value = "2" And Cells(24, 7).Value = 0 Then
            Range("G24").Value = 1
            Range("W63").Value = 1
        ElseIf Cells(59, 23).Value = "2" Then
            Range("G24").Value = Range("G24").Value + 1
            Range("W63").Value = Range("W63").Value + 1
            Range("W65").Value = 1
        End If


Und dann ging es nicht mehr.

Der geht z.b. :

Private Sub H2_Click()


Code:
If Cells(59, 23).Value = "0" Then
    MsgBox "Bitte erst Spieler zum Board!"
Else
    If Cells(23, 12).Value = "0" And Cells(23, 13).Value = "0" Then
        If Cells(59, 23).Value = "1" And Cells(23, 14).Value = 0 Then
            Range("N23").Value = 1
            Range("W64").Value = 1
        ElseIf Cells(59, 23).Value = "1" And Cells(59, 64).Value = 0 Then
            Range("N23").Value = Range("N23").Value + 1
            Range("W64").Value = Range("W64").Value + 1
        End If
    ElseIf Cells(23, 12).Value = 1 Or Cells(23, 13).Value = 1 Then
        MsgBox "Spiel Fertig!"
    End If
End If

End Sub
Habe die Lösung gefunden Wink einfach blödes denken und nicht achtgeben.

Da die

Code:
Cells(24, 4).Value = "0" And Cells(24, 5).Value = "0"

Natürlich noch auf 0 Standen, da Sie erst im nächsten lauf auf 1 Gesetzt werden, ist er immer hier reingelaufen, da in diesem if aber keine bedingung stimmte einfach ohne was zu machen durch.

Nach dem ich die zeile erweitert habe :

Code:
    ElseIf Cells(24, 4).Value = 0 And Cells(24, 5).Value = 0 And Range("W59").Value = 2 Then


Geht es Wink

Lg