Bonsoir, j’ai un projet qui consiste a créer un 2048 sous excel VBA
Je cherche le déplacement à gauche avec des boucles For et if
j’ai deja le déplacement à droite,
Sub droite()
For i = 4 To 7
For j = 2 To 4
If Cells(i, j + 1) = 0 Then
Cells(i, j + 1) = Cells(i, j)
Cells(i, j) = “”
Else
If Cells(i, j + 1) = Cells(i, j) Then
Cells(i, j + 1) = Cells(i, j + 1) * 2
Cells(i, j) = “”
End If
End If
Next j
Next i
generer
end sub
pour le déplacement à gauche, j’ai fais ca :
Sub gauche()
For i = 4 To 7
For j = 3 To 5
If Cells(i, j - 1) = 0 Then
Cells(i, j - 1) = Cells(i, j)
Cells(i, j) = ""
Else
If Cells(i, j - 1) = Cells(i, j) Then
Cells(i, j - 1) = Cells(i, j - 1) * 2
Cells(i, j) = ""
End If
End If
Next j
Next i
generer
End Sub
je pense que pour que la macro marche, il faudrait que j’inverse “For j= 3 to 5” en “For f=5 to 3”
Mais quand je fais ca, rien ne se passe .
comment puis-je arranger le problème ?
Je suis en apprentissage de programmation de base, donc je cherche pas un truc de fou …
merci en avance, bonne soirée